最近研究po的思想,看到别的的码,顺便时间一下,用的qq邮箱做的例子,步骤如下:
第一步:创建页面类,页面元素设置为类属性,操作设置为方法;
@FindBy(xpath="//*[@id=\"switcher_plogin\"]")
private WebElement switchto;
@FindBy(xpath="//*[@id=\"u\"]" )
private WebElement username;
@FindBy(xpath="//*[@id=\"p\"]" )
private WebElement password;
@FindBy(xpath="//*[@id=\"login_button\"]" )
private WebElement loginBtn;
public void login(WebDriver dr,String username,String pwd){
dr.get("https://mail.qq.com/cgi-bin/loginpage");
dr.switchTo().frame("login_frame");
this.switchto.click();
this.username.sendKeys(username);
this.password.sendKeys(pwd);
loginBtn.click();
}
第二步:创建初始化页面操作类,并调用第一步方法;
2.1初始化页面元素调用方法
@Test(dataProvider = "account")
public void login1(String username, String password)
{
WebDriver driver= new FirefoxDriver();
// 对页面元素的初始化
Mail163 m163 = PageFactory.initElements(driver, Mail163.class);
m163.login(driver, username, password);
}
2.2 提供dataProvider:
@DataProvider(name="account")
public Object[][] logindate() {
return new Object[][]{
{"490153419@qq.com","WWZ-08200"},
};
}