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.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning