Thursday, 4 June 2015

Maven, TestNG and Selenium

Setup:



  1. Eclipse: Download Eclipse from "https://eclipse.org/downloads/"


  1. goto "Help" and click on Eclipse Marketplace




  1. Serach for Maven and click on install












  1. Under "Help" click on "Install New Software"



  1. Click on Add



  1. Enter Name: TestNG and for Location: http://beust.com/eclipse



  1. Select TestNG and click on Next and complete the installation.


Creating Project in Maven

  1. Click on File then New then Other




  1. New window will open. Expand Maven folder and Click on "Maven Project"










  1. Enter Required Group Id: automationTesting, Artifact Id: com.Automation and then Click on Finish



  1. Create your Test/Class under src/test/java



  1. Your class should look like:




  1. Create testng.xml for Test Suite and Test



  1. Create pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>Automation</groupId>
<artifactId>com.project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>com.project</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src/java</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>




RUNNING with MAVEN

  1. Right Click on Project then Run As then "Maven build ..."



  1. Define Goals: as "package" and click on "Run"


No comments:

Post a Comment