如何将Weblement称为其他课程

时间:2016-07-31 16:38:52

标签: oop selenium selenium-webdriver testng assertion

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");
    }

1 个答案:

答案 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");
    }
}