我有一个问题,如何使用Page Object Pattern在我的测试项目中处理继承。在我们公司,我们有一个稳定版本的Web应用程序 - 称为Demo,我们从中复制准备好的模块。类似于其他新版客户端应用程序的基础。他们90%都是一样的。所以我认为制作基页对象类并在许多项目中从这些类继承是很棒的。它们在这10%中是不同的,我需要覆盖类字段中的xpath。当我从Base POP Class继承,在子类中创建一个字段,从父类(Base POP Class)中的方法在父类中的字段上而不是在子类上运行时,我遇到了问题。让我看看你的例子。这可能是父类:
public class BaseHomePage {
@FindBy(xpath = "exampleXpath")
protected WebElement profileButton;
public BaseHomePage(WebDriver driver) {
PageFactory.initElements(driver, this);
}
public void goToProfile() {
profileButton.click();
}
这是我的孩子班:
public class HomePage extends BaseHomePage {
@FindBy(xpath = "otherXpath")
protected WebElement profileButton;
public HomePage(WebDriver driver) {
super(driver);
PageFactory.initElements(driver,this);
}
public void goToProfile() {
profileButton.click();
}
}
所以问题是我需要在子类中使用相同的方法goToProfile(),因为当我没有从父类调用父类的字段时。我不想复制代码并且我会搜索答案,但我不确定这在多个项目中是否能很好地利用POP。我需要做些什么呢?或者你可能会建议我用另一种方式制作它?谢谢你的帮助!