Why should we map the Elements or identifiers or locators in UI?
Imagine that if you have a case with hundreds of input in login field. Now the login text box has been changed to drop down list or the name of the identifier has been changed from Textbox_Login to txt_login.
If we execute our existing test scripts they will fail as they cannot find the locator and making changes in all scripts that involve would be hard.
Hence we map the UI objects & store them in a centralized location for making the script more efficient and maintainable.
So we create a Properties file where we store all the UI objects identifiers & for any further changes we can just tweak this properties file as against all testscripts.
Create the properties file :
Create a file like resLogin.properties and we can assign the UI element as follows:
resuser.firstname = "ctl00_txtFirstName";
resuser.middlename = "ctl00_txtMiddleName";
resuser.lastname = "ctl00_txtLastName";
resuser.loginname = "ctl00_txtLoginName";
resuser.password = "ctl00_txtPassword";
All you have to do now is make a call in your selenium scripts.
For ex :
In the above example for any identifiers being changed you have to make changes in the properties file & replace the one highlighted.