Steps for maven build creation in Selenium

Module 1- Install Maven in local machine.

1- Navigate to Maven official site and download stable version of Maven.



2 –  Unzip the download file and Check unzip folder – in our case folder name- apache-maven-3.3.1



3-  This is maven home directory and now we have to set path for the same




4-     To set path variable- Right Click on my computer and Select property.




5-   Now we need to set path variable also for System variable.
Note- Please do not touch other variable, Go to last point use ; and then enter path till bin folder.





6-  Click on save and apply.  You can verify now that Maven is installed or not.
Open command prompt and type

mvn –version

7-  If Maven is installed properly then you will get Maven version and Java version on Console.

Pre Condition: Create a maven project and create at least one test case.



POM.XML for Selenium maven build 

<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>com.automation.maven</groupId>
<artifactId>com.automation.maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Create Maven build</name>
<description>Create Maven build</description>
<!-- Change from here -->
<packaging>jar</packaging>
<properties>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
</dependency>
<!-- Adding Selenium dependency -->
<dependency>
 <groupId>org.seleniumhq.selenium</groupId>
 <artifactId>selenium-java</artifactId>
 <version>2.47.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles> 
</configuration>
</plugin>
</plugins>
</build>
</project>

My project structure after all the changes.



Once all set you can execute pom.xml. Right click on pom.xml and run as maven test.



Now its time to enjoy because our build is success. Check below screenshot



Reports- You can check default reports which is created and you can see another surfire reports as well.
You can also create XSLT Reports with Maven.



We can also configure Maven with Jenkins and we can run our build periodically.





No comments:

Post a Comment