We have seen Page Object Model in previous posts and you must be noticing that we are writing locators within code. It has its own disadvantages as below:
- For any modification in locator, you must need to touch the code.
- Difficult for manual tester or beginner in automation testing to find out correct place to change locator if needed.
So, we can also read locators from externals sources like:
b. Properties file
c. XML file
d. Excel sheet
Database and Properties file are mostly used as external source of locator to create object repository. We will see how to create object repository using properties file.
What is properties file in Java?
A file with extension .properties in java, is called a property file which stores the data in form of key value pair (Like Map). We can store our locators in a properties file and we can read it from properties file and we can use to create object repository.
How to read data from properties file?
Step 1: Create a file with extension .properties as “locator.properties”.
Step 2: Load the properties file using load() method of Properties class.
Step 3: Use getProperty(String key) to read value using Key.
We will see step by step now.
Step 1: Let’s start by creating a properties file.
We will store the value as:
WebElementName = LocatorType:LocatorValue
It will help in locating web element using desired locator.
Create a class to load properties file:
We will create a class which will have methods for loading properties file and locating web element .
That’s it guys. Hope you would have clear concepts now.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.