Text in ORANGE has to be edited by users or mentioned important through-out this BLOG
Maven is the Central Repository [like a server], where it can store the jar files. Here, we use Maven as a test execution framework.
Set Maven Environment
1| Download
Maven apache-maven-x.x.x-bin.zip
2| Unzip the folder under
C:\Program Files\
3| Create a new System Variable under 'Environment Variables'.
Variable:
M2_HOME
Value:
C:\Program Files\apache-maven-3.0.4
4| Add Maven path under the variable name, 'Path'
Variable value:
%M2_HOME%\bin
5| Make sure that maven is configured properly.
6| Open cmd prompt.
7|Type
'mvn -version'
Configure Maven on Eclipse
1| Install Maven plugin in Eclipse IDE using
"Eclipse Marketplace.."
2| Create a new 'Maven project' in Eclipse IDE.
Right click on Package Explorer > New > Other
3| Type 'maven' and Click Next.
4| Select the Project location and Click Next.
5| Select an Archetype as shown below and Click Next.
6| Enter the 'Group Id' and 'Artifact Id' and Click Finish.
7| Now, you will see a POM file created below target folder.
Modify POM.xml
1| Create a new class file under
src/test/java; Here it is
'AppTest.java'
2| Open the POM xml file.
3| Add the following dependencies for a simple test execution.
JUnit, TestNG, selenium-server, selenium-java
This is how the POM looks like,
<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>mvngrp</groupId>
<artifactId>mvnart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mvnart</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.35.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.35.0</version>
</dependency>
</dependencies>
</project>
4| The build libraries mentioned under dependencies will automatically added into the project soon-after saving the POM.xml
Maven Test Execution
There are couple of ways to execute Maven Test.
#1
1| In eclipse,
right click on the POM.xml > Run As > Maven install
2| In-order to clean existing test results, it is important to 'Maven clean' before executing a new test.
right click on the POM.xml > Run As > Maven clean
#2
1| Open cmd prompt.
2| Move into the project folder.
3| Type '
mvn clean'
4| Type '
mvn install' for test execution
Note| If you've trouble on creating Maven projects using
maven-archetype-quickstart [Eclipse],
1| Open cmd prompt
2| Locate the workspace
3| Enter the below to create a maven project
mvn archetype:generate -DgroupId=yourgroupid -DartifactId=yourartifactid -DarchetypeArtifactId=maven-archetype-quickstart