• Selenium Video Tutorials

Selenium with Maven & Jenkins Tutorial



Selenium tests written with the help of Maven can be integrated with Jenkins so that tests can be triggered directly from the continuous integration tools like Jenkins, rather than relying only on local execution from an editor.

What is Maven?

Maven is a project management and comprehension tool that provides developers a complete build lifecycle framework. Development team can automate the project's build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.

In the case of multiple development teams, Maven can set-up the way to work as per standards in a very short time. As most of the project setups are simple and reusable, Maven makes the developer easy while creating reports, checks, build and testing automation setups.

To get more information on the Maven, please refer to the link − Maven.

What is Jenkins?

Jenkins is a powerful application that allows continuous integration and continuous delivery of projects, regardless of the platform you are working on. It is a free source that can handle any kind of build or continuous integration. We can integrate Jenkins with a number of testing and deployment technologies.

Jenkins is a continuous integration tool which is open source and used extensively for building and testing products. It is very helpful from the developers point of view since changes can be incorporated easily to the projects.

In Jenkins the continuous integration is achieved with the help of plugins. While Maven is to be integrated with Jenkins, it can be achieved with the help of Maven specific plugins in Jenkins.

As Maven is integrated with Jenkins using the plugins, it makes it possible to automate the complete build process. Once the plugins are installed, there are certain configurations and settings that should be done to complete the Maven and Jenkins integration. There can be any number of Maven jobs running on the Jenkins server. This also helps to build any Selenium tests built on java available in Git repositories.

To get more information on the Jenkins, please refer to the link − Jenkins.

How to Integrate Maven & Jenkin?

Step 1 − Navigate to the link and download the Jenkins war file − https://www.jenkins.io/download/.

Step 2 − Based on the platform, click and download the Generic Java Package(.war file) for Jenkins. Jenkins can be used on multiple platforms like Windows, Mac, Ubuntu, and so on.

Selenium Maven & Jenkins 1

Step 3 − For MacOS, click on the macOS link, and run the command: brew install jenkins.

Step 4 − Run the command: brew services start jenkins to begin the Jenkins service.

Step 5 − Run the below command −

sudo cat /Users/$(whoami)/.jenkins/secrets/initialAdminPassword. 

This command shall give the initial admin password.

Step 6 − The Jenkins by default runs on the 8080 port. Open a new browser and enter: localhost:8080. The Jenkins home page should be displayed and enter the password obtained in Step5 and then click on the Continue button.

Selenium Maven & Jenkins 2

Step 7 − Click on the Install suggested Plugins and all the suggested plugins will start installing.

Selenium Maven & Jenkins 3

Step 8 − Once all the suggested plugins are installed, create a First Admin User with all the details. Then click on the Save and Continue button.

Selenium Maven & Jenkins 4

Step 9 − Instance Configuration page should come. Click on the Save and Continue button.

Selenium Maven & Jenkins 5

Step 10 − Jenkins is now successfully installed with the message Jenkins is ready!. Click on Start using Jenkins.

Selenium Maven & Jenkins 6

Step 11 − Click on the Manage Jenkins link available on the Jenkins Home Page.

Selenium Maven & Jenkins 7

Step 12 − Click on the Plugins link.

Selenium Maven & Jenkins 8

Step 13 − Click on the Available Plugins, then enter Maven in the Search box. All the available Maven plugins should be displayed for selection. After selection of all the Maven related plugins, click on the Install button.

Selenium Maven & Jenkins 9

Step 14 − Once all the plugins are installed successfully, click on the Restart Jenkins when installation is complete and no jobs are running checkbox.

Selenium Maven & Jenkins 10

Step 15 − Login in to Jenkins with the credentials again.

Selenium Maven & Jenkins 11

Step 16 − Click on the New Item on the Jenkins home page.

Selenium Maven & Jenkins 12

Step 17 − Input a project name, say Hybrid under the Enter an Item name label, then click on the option Maven Project.

Selenium Maven & Jenkins 13

Step 18 − Enter some description under the Description field within the General Tab.

Selenium Maven & Jenkins 14

Step 19 − Select None for the Source Code Management.

Selenium Maven & Jenkins 15

Step 20 − Move to the Build section and click on the tool configuration link.

Selenium Maven & Jenkins 16

Step 21 − Move to the Maven installations section, and then click on the Add Maven button.

Selenium Maven & Jenkins 17

Step 22 − Enter a name under Name and select the latest version Maven from the dropdown. Then click on the Apply and Save buttons.

Selenium Maven & Jenkins 18

Step 23 − Enter the path of the pom.xml of the Maven project under the Root POM field and enter clean install under the Goals and options. Then select the option Run regardless of build result. Finally, click on the Apply and Save buttons.

Selenium Maven & Jenkins 19

Step 24 − Move to the Jenkins Dashboard and click on the Manage Jenkins link.

Selenium Maven & Jenkins 20

Step 25 − Navigate to the Plugins section and install the TestNG Results plugin. Restart the Jenkins once installation is complete.

Selenium Maven & Jenkins 21

Step 26 − In the Jenkins Dashboard, click on the project - Hybrid created before.

Selenium Maven & Jenkins 22

Step 27 − Click on the Configure link at the left.

Selenium Maven & Jenkins 23

Step 28 − Move to the Post-build Actions section.

Selenium Maven & Jenkins 24

Step 29 − Publish TestNG results should be available in the dropdown.

Selenium Maven & Jenkins 25

Step 30 − Select the option Publish TestNG results and click on the Apply and Save buttons.

Step 31 − Click on the Build Now link, to run the test from Jenkins.

Selenium Maven & Jenkins 26

Step 32 − Click on any build number under the Build History.

Selenium Maven & Jenkins 27

Step 33 − Click on Test Result to the left.

Selenium Maven & Jenkins 28

Step 34 − The class name along with the total number of passed, failed, and skipped test cases, and test duration captured in the test result.

Selenium Maven & Jenkins 29

This concludes our comprehensive take on the tutorial on Selenium - Maven & Jenkins. We’ve started with describing what is Maven, what is the use of Jenkins, how to integrate Maven and Jenkins in Selenium.

This equips you with in-depth knowledge of the Selenium - Maven & Jenkins. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements