Friday 22 April 2016

Selenium POM ( Page object model) Project


-          Create a Maven project as explained here. http://kranthikasthuri.blogspot.com/2016/04/how-to-create-maven-project-in-eclipse.html




-          Lets add Selenium and TestNg Maven dependencies in pom.xml

<dependencies>
    <dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-java</artifactId>
       <version>2.53.0</version>
    </dependency>
  
       <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.8</version>
         <scope>test</scope>
       </dependency>
</dependencies>


-          The moment you add above code in pom.xml, IDE starts to download the said jars
-          Now maven dependencies looks like this.





Java coding part:

-          Now create packages for Page object model as shown below.

-          Driver object creation
o   I have used singleton design patterns to create. Here you can find it. http://kranthikasthuri.blogspot.com/2016/04/design-patterns-singleton-single-object.html
o   MyDriver.java contains only Driver object related stuff

-          Now, Lets work on POM
o   What is POM : Segregating Locators , pages and Tests related to each page for better maintenance.
o   This is how I segregated http://theyachtclub.in/  Home Page Locators, Pages and Tests.

-              HomePageLocators
-              HomePage
-              HomePageTests

o   Locators:
§  This this the palace where all your Specific page level locators exists.
o   Pages:
§  This is the places where all your specific page level locators exists

o   Tests:
§  This is the places where all your specific page level Test cases exists


Do you want to see the code?
Here is it.
https://github.com/kasthurikranthikumar/selenium-pom-sample 



-          For Running the project:
o   Right click on POM.xml and select maven test
-          If you are facing any issues please check below points
o   Make sure you had an entry in pom.xml which is related to testing dependency
o   You test class file must end with Test
o   M2_Maven variable must be added