Testbytes IN website

How to Integrate Maven and Jenkins with Selenium 

August 31st, 2018
How to Integrate Maven and Jenkins with Selenium 

Using Selenium test scripts is easy but when it comes to build management and Continuous integration, Selenium alone is not that powerful.That’s why we integrate Maven and Jenkins with Selenium

You need to take help of other tools to integrate Continuous integration and deployment. This is exactly why Maven and Jenkins are needed.
What are Maven and Jenkins?
Jenkins is an open source continuous integration tool and it is cross platform which can be used on Windows, Linux, MAC and Solaris environment.
Jenkin will monitor a job which can be SVN checkout, cron or any application state.
It then fires an action when a particular step occurs in a job. Maven is a build management tool which makes the build process very easy.
With the help of maven you can define your project structure, dependencies and builds.
With the help of pom.xml you can define all the dependencies which would ease the process of build.
Maven automatically download the necessary files from maven repository and place them in. /m2 repository. Hence, we require Maven and Jenkins with Selenium.
Advantages of Using Maven and Jenkins

  • Jenkins provides a way to do smoke testing for every time the code changes and deployed to a new environment. It will make sure that the code is running properly.
  • You cans schedule your test cases with Jenkins so that if regression suite takes almost 6-7 hours to run then you can have nightly build run so that by the time you reach office it will be done.
  • Jenkins server will act as a common server for client as well as technical people to logon to it and see all test reports and test execution history.
  • Maven in turn reduces dependency on hard coding of jars.
  • Maven can make the build process very easy.
  • Also, at some time if you need to update the jars with a specific number, you don’t need to go to Build path and add that particular jar. You can just change the number of version in pom.xml and it will be done.
  • In a team where people are distributed across geographical locations it is easy to share artefact id and version id to clone the project rather than sharing on a common drive.

Steps to Install Maven with TestNg in Selenium
You should have Eclipse installed in your machines. Along with that, you need m2eclispe plug-in which you can download from Eclipse marketplace.
You can go to Eclipse marketplace and then search Maven and the first plug-in which will come, you can download that.
Let’s see how to create a Maven project.

  • Create a new Project by File -> New -> Other and then select Maven -> Maven project.
  • Click on Next and then you have to enter Artifact Id and Group Id. Group Id would be your Project Name and Artifact Id would be your Project folder name.
  • Select a template for your project. Select “Maven quikstart template”.
  • You will then get a WebDriver Test with a folder structure.
  • xml will be shown in the project structure. POM is the heart of the maven. In POM.xml project node you have to add following dependencies.

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<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.8</version>
<scope>test</scope>
</dependency>
</dependencies>

  • This way, you can add dependencies in the POM.xml. You can search for dependency tag in Maven repository.
  • Create a TestNG class with name NewTest.xml and it will also be added to your project structure.
  • Now remember one thing that for running test through maven you need maven surefire plugin and along with testng.xml plugin for integrating with testng. Along with these two things, third plugin Maven compiler plugin is also required which is used for helping in compiling the code.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>TestNG.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

  • Now, you can go to Windows Path where pom.xml is placed. Open cmd there and fire commands.

1. mvn clean
2. mvn compile
3. 0mvn test // for all tests to be executed.
4. mvn -dtest // for a particular test to be executed.
Steps to Install Jenkins with Selenium
Let’s see how to configure Jenkins with Selenium so that client and all technical people would be able to handle a single server for all test results.
1. Click here and download correct package for your operating System. Then you can install Jenkins Unzip Jenkins to a specific folder and run its exe file.
2. When you are done with installation of Jenkins you have to fire a command in cmd to start your jenkins server.
java -jar jenkins.war
3. It will automatically host the server on 8080 port but if you don’t want it to run on 8080 port then you can specify the port number along with the command.
4. After that is done. You can visit https://localhost:8080 You can do the installation of necessary plugins. Then you can click on New Item and then select the Maven project.
5. Then you can click on Ok and a new job will be created with the name specified by you.
6. Now go to Manege Jenkins and then Configure Systems. Configure Maven and JDK there and go to Build Section and enter their full path of your pom.xml.
app testing
7. Now click on Apply. On the main page, click on “Build Now” link. Maven will automatically execute the test. After the build is done click on your project name.
8. In the left sticky bar you can see the execution history. You can click on the latest results to view the test results.
9. Even you cans schedule the test cases with Jenkins. You have to go to modify the configuration and there enter “Build Periodically” and enter the time in the manner like “0 23 * * *”. It will trigger everyday at 11 pm.
Conclusion
This way you can make your build process easier easy and can do continuous integration with Jenkins. This will increase the time efficiency and will help in better management of your test suite.

Recommended For you : 15 Top Selenium WebDriver Commands For Test Automation

Testbytes IN website
Recent Posts
Subscribe
Please enter valid email address

Contact Us
Please type your Name
Please enter valid email address
Please enter phone no.
Please enter message
Testbytes IN website

Search Results for:

Loading...

Contact Us