Test Automation tips - store all locators in one class
When starting on test automation, a frequent mistake is that
each page object class file has its own locators defined as class members:
This can be corrected easily by
moving the locators from all page object class files to a single locator class file.
Solution
A new class is created and the locators from all page object classes are moved into it:
The code from the test class is changed then to use the new locator class:
You can remove the locator members from the HomePageScripts class and just use the Locator class members directly in the WebDriver commands like
WebElement searchLabel = driver.findElement(By.xpath(Locators.searchLabelLocator));If both the Locators class and the page object classes are in the same package, nothing else is needed.
If they are in different packages, you will need to import the Locator class package in the page object class file.
each page object class file has its own locators defined as class members:
This can be corrected easily by
moving the locators from all page object class files to a single locator class file.
Solution
A new class is created and the locators from all page object classes are moved into it:
The code from the test class is changed then to use the new locator class:
You can remove the locator members from the HomePageScripts class and just use the Locator class members directly in the WebDriver commands like
WebElement searchLabel = driver.findElement(By.xpath(Locators.searchLabelLocator));If both the Locators class and the page object classes are in the same package, nothing else is needed.
If they are in different packages, you will need to import the Locator class package in the page object class file.
0 Response to "Test Automation tips - store all locators in one class"
Post a Comment