selenium登录流程 可以参数化吗
selenium登录流程 可以参数化吗如一个java怎么写登录成功、登录失败呢 同问哦 当然可以。。传参数嘛 放数据库 java 反射机制 selenium登录流程 可以参数化吗
如一个java怎么写登录成功、登录失败呢
bokewangyu 发表于 2014-8-2 16:20 http://bbs.51testing.com/images/common/back.gif
package com.webdriver.example;
import static org.junit.Assert.*;
import java.util.concurrent.TimeUnit;
import org.databene.benerator.anno.Source;
import org.databene.feed4junit.Feeder;
import org.junit.runner.RunWith;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@RunWith(Feeder.class)
public class WebDriverlogin {
private static WebDriver driver;
private static String baseUrl;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://127.0.0.0";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
driver.quit();
}
@Source("username.xlsx")
@Test
public void test(String username,String password) {
driver.get(baseUrl + "/");
driver.findElement(By.name("username")).clear();
driver.findElement(By.name("username")).sendKeys(username);
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.cssSelector("input")).click();
if(username.contains("username1")){
SeleneseTestBase.seleniumEquals("xxxxxx", driver.getTitle());
driver.findElement(By.linkText("安全退出")).click();
}else if(username.contains("username2")||username.contains(" ")){
SeleneseTestBase.seleniumEquals("xxxxxx", driver.getTitle());
assertEquals("您操作失败了!可能因为:用户名错误!", driver.findElement(By.xpath("html/body/div/div/div")).getText());
}else if(username.contains("username3")){
SeleneseTestBase.seleniumEquals("xxxxxx", driver.getTitle());
assertEquals("您操作失败了!可能因为:密码错误!", driver.findElement(By.xpath("html/body/div/div/div")).getText());
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
页:
[1]