Jenkins Continuous Integration: Build your Selenium Maven Project

Continuous Integration is on trend so is the DevOps. You would have mastery over Selenium WebDriver or Automation Framework development, but all your knowledge is incomplete without the knowledge of the DevOps or Continous Integration. It has an added benefit to your knowledge. Today not only testing processes are in automation, rather the entire lifecycle automated and it became possible when Development, Operations and other Stakeholders came under the same umbrella which we call as DevOps. Basically, we connect other tech environments with the help of pipeline and the status of the pipeline tracked and triggered through the build. Continuous integration tool generated these builds. There are some paid and free tools available. Some of the tools are- Jenkins, Bamboo, Team City, etc.

Jenkins, the most popularly used CI tool. Today we are going to discuss this wonderful tool and its configuration with your Maven project. We will also see how builds are triggered automatically when we run our test in Eclipse and Test results validation after doing the manual run of the build in Jenkins.

Recommended: Log4j Logging Configuration in Selenium Automation Framework

What is Jenkins?

Jenkins is a CI (Continuous Integration) tool which is written in Java. This is a Hudson project which is basically an open source. It offers services like Continuous delivery and Integration.

We can use on Windows, Linux, Mac OS etc environment.

Now one question comes in our mind that why we use Jenkins in selenium.

The answer is if the software changes or deployed in a new environment Jenkins is able to run test scripts every time to ensure whether the code is the break or not. That’s why Jenkins is called continuous integration tool. We can also schedule our test script at the specific time and it generates the test report as well.

How to download and configure the Jenkins?

Step# 1: Click here to download the installation file for your Operating system.

Step# 2: Install Jenkins. If you are using windows OS then download for windows

Window jenkins download

Step# 3: Unzip Jenkins to the specified folder and continue to install.

Jenkins Installer file

Step# 4: Click on next

Jenkins Install

Click on Install to complete the installation process. The following page appears after the completion of the installation.

Unlock jenkins empty

Now go to the below directory in your system and copy the password from the red circle file.

C:\Program Files\Jenkins\secrets


Now paste the copied password into the Administration password’s field then continue.

unlock jenkins

From here you must reset your username and password.

Click on Save and Continue.

Jenkins first admin user

Jenkins instance configuration

Now you will be redirected to Jenkins home page. You can now create a new job.

How to create the Maven project in Jenkins?

Click on New Item to create the job then select the maven project from the options. Follow these steps:

First Jenkins inviul project

Click on Ok

If, in case, you are not getting Maven project option then you need to download maven plugin from manage Jenkins option.

Manage jenkins

Click on manage plugins.

Manage plugin

If Maven plugin is not there in the installed list then search for the maven from the Available section. Further, wait for the plugin to get installed in Jenkins.

Now it will prompt you to restart your Jenkins server, hence you can proceed to do that.

maven integration

Now create your first job to trigger build from Jenkins. Scroll down further until you get build section.

Build Jenkins

Enter the path to your pom.xml as the value in the Root POM text area, and enter clean test in Goals and Options text area. See the image below.

Clean test

If you get an error as shown in the below screenshot then click on the tool configuration link and proceed as per the below steps:

build maven error

Step# 1: Enter the java_home

Global tool config

Step# 2: Click on add maven and enter the maven name and maven home

Maven home

Now your maven is set and you can continue to further configurations.

How to set up periodic builds in Jenkins?

If you want to run your build for specific time interval then go to build triggers and select build periodically by entering the job pattern.

Click on apply and save

Build Triggers

I entered * * * * * which means it will run my job every minute

Explanations of above build logic/pattern

Let’s say we assign each star some numeric position (first, second,..) for our convenience to explain this logic So here the first star denotes minute whose range is between 0 to 59. Similarly, the second star denotes hour with range from 0 to 23, the third star denotes the day of the month which lies between 1 to 31, fourth star means that the month whose range lies between 1 to 12 and the fifth the last star denotes day of the week whose range is between 0 to 6 (Sunday to Saturday).

How to configure email in Jenkins build?

If you want to send email after the build based on the build status then you can add email of the recipients.

eclipse and jenkins

Now click on apply and save.

Job Created Successfully:

You get your job successfully done.

eclipse and jenkins

Click on “build now” from the left pane.

Your build starts running.

I have created a simple project which will validate the title of Google homepage

eclipse and jenkins

Here is the above code, if you wish to use it:

Click on Console Output to see the results of the build and test as well.

Console Output

Here is the result.

Result Jenkins

Hope you liked this thorough step by step guide to set up and configure your Selenium Maven project with CI tool. If you liked this tutorial and spread the knowledge among your friends because Learning is Sharing. You can share your queries, doubts, and feedback in the comment below. You can also join our Facebook group for latest updates on Selenium and Automation testing. We are sharing lots of cool stuff and knowledge over there.

If you also want to share awesome tutorial like this then get in touch with us; Also, you can come up with your ideas.

Join Our FacebookGroup

Join Inviul fb group


Leave a Reply