Handling the case when users get different main pages based on usertype after login

  • It's more like a theoretical question and I am seeking the best practice here.

    Given an application where you have different user types, newly registered users get a new UI while old users are getting the old UI.

    When you login with a user you are getting into a main page where your user can do stuff, but the two UIs are very much different (different buttons, elements with different locators) except search bar and some others.

    I have thought about a few options here:

    a. Create seperate page objects (AMainPage, BMainPage) for the two landing pages which both implements an IMainPage interface and use them like

    LoginPage loginPage = new LoginPage(GetDriver());
    IMainPage mainPage = loginPage.loginWithUser(user);

    And then implement the login something like

    public IMainPage loginWithUser(User user)
    //implement the actual action
    //return page object based on user.UserType (e.g. AMainPage or BMainPage)

    b. Similar to the first but with an abstract parent which implements the actions where the two UIs are the same, and define other actions where it differs.

    c. Use one common page object to implement all actions for both UIs.

    Or something else could be better? Suggestions?

  • (c) clearly breaks the Single Responsibility Principle (SRP) (a) would result in duplicated code, which is solved by (b).

    A few other things you can do would depend on how you control the environment.

    You can have different login page objects for each user type, which implement the method login returning the user-specific main page. This way, you replace a if/switch for polymorphism, which is more extendable.

    Then a factory can create the specific Login Page based on test data (data provider).

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2