3

[This is cross-posted from StackOverflow - https://stackoverflow.com/questions/51702719/using-different-sets-of-page-objects-with-the-same-selenium-tests]

I'm working on a selenium test suite for a set of similar websites. The test suite would be execute separately for each site and the tests in the suite are applicable to all websites.

These websites are built on the same underlying platform, however have different theme/scheme and therefore page objects for these sites need to be different. This is not a case of one or two selectors being different, but majority of selectors different - yet the rest of the structure is the same.

I can easily create two (or three, or whatever) sets of page objects, however I can't figure out how to tell the test executor (Cucumber cli in my case) which page objects to use.

The closest I can come up with is use different package names with common base classes and then individual pages extending from the common base classes. Another possibility is to extract all the selectors into property files and load one or another based on an input parameter, however this would preclude me from using PageFactory. I can also, probably, create separate sets of page objects in different source sets and then compile one or the other based on my need - but, again, I can think of the theory, yet not the execution.

So, what's the right approach and how to achieve this? If it matters, the project is built using gradle.

2 Answers 2

1

Test Executors have nothing to do with how you tell Selenium which objects to use. Personally I do not see any benefit of using PageFactory in the situation like yours. Having stuck to page objects you will have to maintain different sets of objects for each your site which means if the objects set will change you will have to amend all your Page classes.

I would approach with having regular way of looking up the elements and having the particular paths in properties. When you run that code from wherever you want (e.g. Cucumber CLI - frankly speaking I am not even aware of what it is) you can set the path to your properties for any particular run as environment variable and read that value from your code.

1

From your question, it looks like applying the Dependency Injection (https://en.wikipedia.org/wiki/Dependency_injection) may solve the issue.

That means that you will need to program against the abstraction, rather the concrete implementation of each PageObject (e.g. using the interfaces, that will provide contract for particular page within your tests) and resolve the dependency before the test start depending on some flag (for example configuration parameter what site you need to use).

In this case, you will still need to have your code organized the site-centric way, e.g. each site UI mapping/PageObjects would be extracted in the separate project.

And this approach would only work if the business logic of the applications/test scenario flow is the same for both sites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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