【发布时间】:2019-11-18 21:30:24
【问题描述】:
我是自动化测试的新手,我的任务是使用给定的注册表实现自动化注册学生。
这个场景让我对如何验证注册表单中的输入字段有点困惑。
我的意思是,如果我没有填写必填字段,浏览器会提示我必须填写该字段。
另一件事是我为 2 名学生使用 for loop,我希望第一次将输入字段留空。提交后,我必须看到它已经过验证,然后填写空输入字段以再次提交(现在在字段中插入数据)。
我正在分享我的代码,希望能提供任何帮助。
public class Cartus {
public static void fill() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "E:\\workspace\\chromeDriver\\chromeDriver.exe");
ChromeDriver driver = new ChromeDriver();
for(int i=0; i<2; i++) {
driver.get("http://qa-5.ls.vu/v2/landing-page/cartus/en");
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[1]/div")).click();
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[1]/div/select/option[2]")).click();
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[1]/input")).sendKeys(/*"sami"*/);
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[2]/input")).sendKeys(/*"Mohaname"*/);
WebElement ele=driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/input"));/*.sendKeys("0221-1234567");*/
String date = FastDateFormat.getInstance("yyyyMMddHHmmss").format(System.currentTimeMillis());
Thread.sleep(1000);
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/input"))
.sendKeys(/*"aali_"+date+"@outlook.com"*/);
driver.findElement(By.id("submitButton")).click();
if(ele.getAttribute("value").isEmpty()){
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[1]/input")).sendKeys("abcds");
}
if(ele.getAttribute("value").isEmpty()){
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[2]/input")).sendKeys("abcds");
}
if(ele.getAttribute("value").isEmpty()){
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/input")).sendKeys("abcds");
}
if(ele.getAttribute("value").isEmpty()){
driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/input")).sendKeys("aali_"+date+"@outlook.com");
}
System.out.println("Test case succesfully run");
}
}
}
谢谢。
【问题讨论】:
标签: java selenium selenium-webdriver automation