selenium1的java代码怎么进行数据的参数化啊?数据驱动可以做,但是我就知道这个概念,谁有个实际例子
1个回答
展开全部
参数化:
public class testSchoolRoom {
public WebDriver driver;
public String baseUrl = "http://wuhan.eduyun.cn";
public String LinkTest;
public String LinkTestPassWord;
public void startUrl() throws Exception {
driver = new FirefoxDriver();
driver.get(baseUrl);
// driver.manage().window().maximize();
}
@DataProvider(name = "testData")
public Object[][] testNetHomeWrok_data() {
return new Object[][] { { "300522624", "1234", "f","密码长度在6-20之间" },
{ "300522624", "123456789","f","密码输入有误" },
{ "300522624", "1234qwer", "t","王丽娟的工作空间" }};
}
@Test(dataProvider = "testData")
public void testTcShortPasswordLg(String userName, String passWord,String flag,
String excepted) throws Exception {
startUrl();
driver.findElement(By.id("info_username")).clear();
driver.findElement(By.id("info_username")).sendKeys(userName);
driver.findElement(By.id("info_password")).clear();
driver.findElement(By.id("info_password")).sendKeys(passWord);
driver.findElement(By.id("info_submit")).click();
if(flag == "t"){
LinkTest = driver.findElement(By.xpath("//li[contains(concat(' ', @class, ' '), ' jykj_blue ')]//strong")).getText().trim();
assertEquals(excepted, LinkTest);
LinkTest = null;
Thread.sleep(2000);
}else{
LinkTest = driver.findElement(By.xpath("//p[contains(concat(' ', @class, ' '), ' warnmsg ')] "))
.getText().trim();
assertEquals(excepted, LinkTest);
LinkTest = null;
Thread.sleep(2000);
}
driver.quit();
}
}
public class testSchoolRoom {
public WebDriver driver;
public String baseUrl = "http://wuhan.eduyun.cn";
public String LinkTest;
public String LinkTestPassWord;
public void startUrl() throws Exception {
driver = new FirefoxDriver();
driver.get(baseUrl);
// driver.manage().window().maximize();
}
@DataProvider(name = "testData")
public Object[][] testNetHomeWrok_data() {
return new Object[][] { { "300522624", "1234", "f","密码长度在6-20之间" },
{ "300522624", "123456789","f","密码输入有误" },
{ "300522624", "1234qwer", "t","王丽娟的工作空间" }};
}
@Test(dataProvider = "testData")
public void testTcShortPasswordLg(String userName, String passWord,String flag,
String excepted) throws Exception {
startUrl();
driver.findElement(By.id("info_username")).clear();
driver.findElement(By.id("info_username")).sendKeys(userName);
driver.findElement(By.id("info_password")).clear();
driver.findElement(By.id("info_password")).sendKeys(passWord);
driver.findElement(By.id("info_submit")).click();
if(flag == "t"){
LinkTest = driver.findElement(By.xpath("//li[contains(concat(' ', @class, ' '), ' jykj_blue ')]//strong")).getText().trim();
assertEquals(excepted, LinkTest);
LinkTest = null;
Thread.sleep(2000);
}else{
LinkTest = driver.findElement(By.xpath("//p[contains(concat(' ', @class, ' '), ' warnmsg ')] "))
.getText().trim();
assertEquals(excepted, LinkTest);
LinkTest = null;
Thread.sleep(2000);
}
driver.quit();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询