Setup:
- Eclipse: Download Eclipse from "https://eclipse.org/downloads/"
- goto "Help" and click on Eclipse Marketplace
- Serach for Maven and click on install
- Under "Help" click on "Install New Software"
- Click on Add
- Enter Name: TestNG and for Location: http://beust.com/eclipse
- Select TestNG and click on Next and complete the installation.
Creating
Project in Maven
- Click on File then New then Other
- New window will open. Expand Maven folder and Click on "Maven Project"
- Enter Required Group Id: automationTesting, Artifact Id: com.Automation and then Click on Finish
- Create your Test/Class under src/test/java
- Your class should look like:
- Create testng.xml for Test Suite and Test
- 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
- Right Click on Project then Run As then "Maven build ..."
- Define Goals: as "package" and click on "Run"