-1

I need to test web page, so we build pages via enum class. In first enum class we have Pages and in second enum we have saved type of pages like "uk", "canada" it , because different type of page need to create different page

I try to user solution from these topic 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;
    }

Ass you can see error occurs in enum class because for example 'new HomePage()' need Storefront param and I don't have any idea how to solve it...

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • 1
    The Java enum facility is appropriate for representing information, all of which is known at compile time. The enum data is therefore static, fixed, and instance controlled. This description does not remind me very much of web pages. – scottb Nov 06 '19 at 21:43

1 Answers1

0

I wouldn't go using enums to store instance of your pages. Why not have a service class which contains a Map<Page, ? extends BasePage> and store all of your pages in there. Then you can have a factory builder or constructor for your service which instantiates the map with all of the required pages.

Adam
  • 1,724
  • 13
  • 16