public class HomePage
{
public HomePage clickAboutUs1Link()
{
aboutUs1.click();
return this;
}
public void clickAboutUs1Link()
{
aboutUs1.click();
}
}
[我将在我的测试类中调用action方法。因此,在将页面对象模型与Selenium Webdriver一起使用时,使用>任何一个有什么优点或缺点?
如果您有更多方法,此问题将更加清楚。考虑那些类
public class HomePage {
public AboutUsPage clickAboutUsLinkAndGoToAboutUsPage() {
aboutUs1.click();
return new AboutUsPage();
}
public HomePage typeToField() {
aboutUs1.click();
return this;
}
public HomePage clickOnChecbox() {
aboutUs1.click();
return this;
}
}
class AboutUsPage {
public boolean isAboutUsPageDisplayed() {
return someElement.isDisplayed();
}
}
现在您可以在测试中使用方法链接来创建流程
public class TestAboutUsLink {
boolean isDisplayed =
new HomePage()
.typeToField()
.clickOnChecbox()
.clickAboutUsLinkAndGoToAboutUsPage()
.isAboutUsPageDisplayed();
assertTrue(isDisplayed);
}
如果每个方法都没有返回任何内容
public class TestAboutUsLink {
HomePage homePage = new HomePage();
homePage.typeToField();
homePage.clickOnChecbox();
homePage.clickAboutUsLinkAndGoToAboutUsPage()
AboutUsPage aboutUsPage = new AboutUsPage();
boolean isDisplayed = aboutUsPage.isAboutUsPageDisplayed();
assertTrue(isDisplayed);
}