gpt4 book ai didi

java - 如何在 selenium webdriver 中为已注册的用户名/email_id 编写脚本

转载 作者:行者123 更新时间:2023-12-01 11:19:28 25 4
gpt4 key购买 nike

我的Java

public class Verifyregistration {
String Verifyregistration_Status = null;
String Verifyregistration_Message = null;

@Test
@Parameters({"USERNAME", "NAME", "EMAIL", "CHOOSEPASS", "CONFIRMPASS"})
public void Execute(String UserName, String Name, String Email, String Choose_Pass, String Confirm_Pass) {
try {

Config.driver.findElement(By.linkText("Register")).click();
Config.driver.findElement(By.id("signup_username")).sendKeys(UserName);
Config.driver.findElement(By.id("field_1")).sendKeys(Name);
Config.driver.findElement(By.id("signup_email")).sendKeys(Email);
Config.driver.findElement(By.id("signup_password")).sendKeys(Choose_Pass);
Config.driver.findElement(By.id("signup_password_confirm")).sendKeys(Confirm_Pass);
Config.driver.findElement(By.id("signup_submit")).click();
//perform validation here
boolean expvalue = Config.driver.findElement(By.xpath("//input[@id='signup_username']/preceding-sibling::*[1]")).isDisplayed();
if (expvalue) {
Verifyregistration_Status = "PASS";
Verifyregistration_Message = "Sorry, that username already exists!";
}
} catch (Exception generalException) {
Verifyregistration_Status = "FAIL";
Verifyregistration_Message = "Verify Registration Successfull";
} finally {
Assert.assertTrue(Verifyregistration_Message, Verifyregistration_Status.equalsIgnoreCase("PASS"));
}
}
}

我已经写了上面的脚本来检查已经注册的用户名/email_id的注册。我只是从错误消息中检查已经注册的用户名的注册。所以我的问题是,我要走对了,否则会有另一个逻辑来检查注册已经有用户名/电子邮件地址。有什么帮助吗?

最佳答案

我建议您使用下面的代码,

公共(public)类验证注册{

String Verifyregistration_Status = null;
String Verifyregistration_Message = null;

@Test
@Parameters({ "USERNAME", "NAME", "EMAIL", "CHOOSEPASS", "CONFIRMPASS" })
public void Execute(String UserName, String Name, String Email,
String Choose_Pass, String Confirm_Pass) {

// Below loop will execute two times
// First Iteration , registration should be successful
// Second Iteration Registration should fail saying "already registered" as i am using same data

for (int i = 0; i < 2; i++) {

Config.driver.findElement(By.linkText("Register")).click();
Config.driver.findElement(By.id("signup_username")).sendKeys(
UserName);
Config.driver.findElement(By.id("field_1")).sendKeys(Name);
Config.driver.findElement(By.id("signup_email")).sendKeys(Email);
Config.driver.findElement(By.id("signup_password")).sendKeys(
Choose_Pass);
Config.driver.findElement(By.id("signup_password_confirm"))
.sendKeys(Confirm_Pass);
Config.driver.findElement(By.id("signup_submit")).click();
// perform validation here
boolean expvalue = Config.driver
.findElement(
By.xpath("//input[@id='signup_username']/preceding-sibling::*[1]"))
.isDisplayed();

if (i==0) {

Assert.assertFalse(expvalue);

}else{

Assert.assertTrue(expvalue);

}


}
}

}

关于java - 如何在 selenium webdriver 中为已注册的用户名/email_id 编写脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com