I have a test suite that currently runs across different development environments. Recently a complete rewrite of the application was done & deployed to a new environment.
The application looks & acts almost identically. Page logic is more or less the same. The big difference is the HTML rewrite has rendered my locators useless. I am unsure how to deal with the locators for this new environment while at the same time adhering to the page object model.
The page object model states that all page logic should be kept in the respective page object class. I am assuming that this includes locators as well.
Following this strategy would leave me with a bloated page object class full of duplicate locators. Is there any recommended best practices or clean solutions to combat this problem ?
The possible solutions i can think of are:
- Create separate locator files for each environment and remove them from the page object class.
- Create duplicate or similarly named locators in the current page object class
- Create seperate page objects for the new environment
Can anyody comment on whether or not these solutions sound ok ? Or offer any alternative suggestions ?
Would definitely move the locators outside the pageobject class into two different classes, one for the old locators and one for the new locators. Use public static final String for each locator. The problem you are going to have is that Java annotation values require constant expression, so you cannot use a method to send different locator to the FindBy. But you can use a ternary operator to create a constant expression.
Below I have added code which on the basis of the global flag clicks on a different button from a single WebElement but the locator is changed by an expression on the 'using' value of the FindBy annotation. You can set the value of the global flag on startup when you initialize a driver from a properties file.
This is what you will need to include in the FindBy and locators sent to findElement() - using= GlobalFlag.devEnv ? NewLocators.newLocxpath : OldLocators.newLocxpath. This will be a pain to copy paste everywhere.
You can try out the code as the website is publicly available.