You must have noticed that we are using Action Keywords like ‘click_MyAccount()‘, which is not at all a good practice. As there will be thousand of elements in any application and to click those elements we have to write thousands of click action keywords. So ideally there will be just one click action which should work on every other element on the test application. To achieve that, it is needed to separate the action from the object. For e.g. there will be a object called ‘MyAccount’ and an action called ‘click()’and it would work like this: ‘MyAccount.click()’

So our next task is to separate all the objects from the actions. To achieve that we need to create an Object Repository, which will hold all the objects properties in it and then those properties can be used in the main driver script. We can easily do this with the help of Property file. Normally, Java properties file is used to store project configuration data or settings. In this tutorial, we will show you how to set up and use a properties file. Time for action now.

Step 1: Set Up Object Repository properties file

Create a new property file by right clicking on ‘config‘ package and select New > File and name it as ‘OR‘.

Now take out all the object properties from Action Keywords class and put in ‘OR’ file.

All the objects will be defined like this: Object Name = Object Property, where object property is element locator.

Note:We have still used ‘input_Password()’ and not detached this object from action. We will take care of this in next coming chapter of Data Driven.

Note:If you see carefully, object argument is passed in every method, even if it is not required in the method, such as ‘closeBrowser()’. This is the mandatory condition of the reflection class that all the methods will have same arguments, even if the argument is not used in some methods.

Step 4: Changes in Constants class

New entry in Constants class for the new column of Page Objects.

Modify the value of the Action Keyword column, as we inserted a new column before the Action Keword column in dataEngine excel sheet.