How To Create Properties File In Selenium
What are Properties file and why we need it? In Selenium web driver there is not any build in facility to create object repository, so maintenance of page objects.
In this post, we are explaining how to read data from properties file using TestNG framework. In our previous post, we’ve illustrated the same concept i.e.
Here, we’ll use both the TestNG framework and the Selenium Webdriver API. We did this post to demonstrate how the TestNG framework can extend the capability of a Selenium Webdriver project. You can learn the whole concept from the below example of the Selenium Webdriver project to read data from properties file using TestNG framework.
Comment In Properties File
UI Map / Object Repository UIMap is a concept for defining, storing, and serving UI elements of an application or a website. The UIMap properties file contains a set of ‘key-value’ pairs, where key is an alias of the UI element, and a value is the locator. We will create properties file for every single page and capture all the UI elements present on the page and use it as per needs. UI Map or Object Repository Samples: - Role - System Admin ManageUsers.Properties ManageDepartments.Properties ManageLocations.Properties Example:- ManageUsers.Properties Why and How to use UI Map / Object Repository / OR To perform any action we need locators. Tool will perform any action based on the locators. For each and every action tool depends on these locators. If the tool does not identify the locators, it simply throws an error as Locator / Element Not Found or Identified.
In order to make sure the tool executes smoothly, we need to provide accurate unique identifier / locators. We need to keep all the locators at one place where we can easily modify the locators / identifies if there are any UI changes in the application. If not, it will become difficult to change even one locator, as it will be used at many different places in test scripts. It is always better to keep locators in a separate file and at easily accessible location. It should be defined in such a way if any new person joins in the middle of the project, he/she should be capable of making changes / adding any new locators to the file.
Properties File Java
In the above example, we have created properties file for each function which will store all the UI elements. Example: In Manage Users, we will store all the locators’ / UI elements information which can be used and accessed in “Add Users”, “Edit Users” and “Delete Users” test cases.