我需要测试网页,因此我们通过枚举类构建页面。在第一个枚举类中,我们有Pages,在第二个枚举类中,我们保存了诸如“ uk”,“ canada”之类的页面类型,因为不同类型的页面需要创建不同的页面
我尝试从Can I use the builder pattern on a Java Enum这些主题中寻求用户解决方案
public class HomePage extends BasePage {
public String url = "/ccrz__HomePage";
public Storefront storefront;
@FindBy(how = How.XPATH,using = "//div[contains(@class,'cc_tmpl_HomePage')]")
private WebElement mainContainer;
public HomePage(Storefront storefront) {
super(storefront);
super.setUrl(this.url);
}
@Override
public boolean validatePage() {
return isDisplayed(mainContainer);
}
public enum Pages {
HOMEPAGE(new HomePage()),ORDER_HISTORY_PAGE(new MyaccountOrderHistoryPage()),MY_accOUNT_PAGE(new MyaccountPage()),private final BasePage page;
private final Storefront storefront;
Pages(BasePage page,Storefront storefront) {
this.page = page;
this.storefront = storefront;
}
public BasePage get() {
return this.page;
}
您可以看到枚举类中发生错误,因为例如'new HomePage()'需要Storefront参数,而我不知道如何解决...