public class LoginPagePages {
@FindBy(how=How.XPATH,using="//div[@class='validation-summary-errors text-danger']/ul/li")
WebElement incorrect_username;
}
如何将WebElement incorrect_username;
传递给班级LoginPageTestCase
,以便我可以将其文本转换为String errorsign
并将其用于我的断言
public class LoginPageTestCase {
@Test(priority=1)
public void IncorrectPassword() {
String errorsign = I NEED TO CALL HERE THE "WebElement incorrect_username".getText();
Assert.assertEquals(errorsign, "Username is incorrect");
Add_Log.info("Login Failed");
}
答案 0 :(得分:1)
您可以在测试中创建LoginPagePages
的实例,并使用getter获取它
public class LoginPagePages {
@FindBy(how=How.XPATH,using="//div[@class='validation-summary-errors text-danger']/ul/li")
private WebElement incorrect_username;
public WebElement getIncorrectUsername {
return incorrect_username;
}
}
public class LoginPageTestCase {
@Test(priority=1)
public void IncorrectPassword() {
LoginPagePages loginPage = new LoginPagePages();
String errorsign = loginPage.getIncorrectUsername().getText();
Assert.assertEquals(errorsign, "Username is incorrect");
Add_Log.info("Login Failed");
}
}