2 Ways to make a Repository of WebElements WebDriver

Hello my friends ūüôā

I hope that you are ok !! I will post today a technique to save the webelements in one file, or in various files but more organized and with this is easier to do maintenance when the website have some xpath, id, classname, tagname or link modified. I used this repository on xml in Bovespa. In this post I will show 2 ways to do this repository:

 

  • First – Create a class with the objects:

–¬†¬†Create the project, you may follow the structure bellow:

OR-2-1

РCreate a  class under testObjects Package (PageLogin.java)

РCreate a  class under testScripts Package  (TestPageLogin.java)

–¬†Open your PageLogin.java¬†and write the code :
1
Don’t forget the package of this class is¬†testObjects, so put in the first line:
package testObjects;

 

РAfter this, open TestPageLogin.Java and write :
 

2

Don’t forget the package of this class is¬†testScripts, so put in the first line:

package testScripts;

 

  • Second – Create a OR file (You can use XML too)

–¬†Create the project, you may follow the structure bellow:

OR-1.1

РCreate a text file with the Extension as .OR  under the object Repository Package (in this case: com.sagara.objectrepository)

 

– Create a java class under test Pages package (in this case: com.sagara.testPages)

 

– Open your .OR file and write the objects informations with a structure like this:

 

1

– Open your class Java and write the below code to get the objects¬†information’s¬†from the OR file and use it:

2

I hope that I has helped, if you have some doubts just let your comment ūüôā

Bye guys !

Font: http://way2automationtesting.blogspot.in/2014/02/creating-object-repository-in-selenium.html