0

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?

0

(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).

  • Thanks for your reply. "You can have different login page objects for each user type" Maybe I'm misunderstanding you, but both users have the same login page; if I'd create a seperate login page for each usertype it would also be code duplication. Also, one another thing I wanted to ask. If I go with solution B, then I would have to inject the usertype to every action which returns to the Main Page, just to return with AMainPage, BMainPage based on usertype, which would end up in a lot of if/else statements and yet again, duplication. Do you have any suggestions the handle this? – dtoman Jun 10 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.