TA的每日心情 | 奋斗 2016-2-2 10:12 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
登录的一个小例子:class LoginPage {
//用户名
@FindBy(id = "txtUserName")
private WebElement username;
//密码
@FindBy(id = "txtPassword")
private WebElement password;
//登录按钮
@FindBy(id = "btnLogin")
private WebElement btn;
//输入用户名和密码,点击登录
public void login(WebDriver driver, String username, String password) {
this.username.sendKeys(username);
this.password.sendKeys(password);
this.btn.click();
}
public boolean loginAction(WebDriver driver, String username, String password) {
LoginPage lp = PageFactory.initElements(driver, LoginPage.class);
lp.login(driver, username, password);
return driver.getCurrentUrl().contains("indexWizard.aspx");
}
}
TestCase:
@Test
public void login() throws InterruptedException {
LoginPage lp = new LoginPage();
Assert.assertTrue(lp.loginAction(driver,"XXX","XXX"));
}
xpath变化后只需要修改Page类,Page存放所有需要的页面,以及对元素的操作。第一次分享有不足的地方,请谅解
|
|