Integrating Maven and Jenkins with Selenium
Before we proceed with maven integration, let’s have a look at what continuous integration is.
Continuous integration(CI) is a development practice of automating the build and testing of code every time a team member commits changes to version control. There are many CI tools such as Jenkins, Teamcity, CircleCI and commercial tools such as Azure DevOps. Jenkins is the most popular CI tool out of all the tools which are available.
❔ Why continuous integration?
The main goal of continuous integration is to identify problems that may occur during the development process as early as possible to send the results to the project team. For instance, when one of the developers in your team is pushing the code, a CI job will be triggered by SVN. If there are already written unit test cases those will be executed first. Then, the automation code will be executed depending on what you want to execute. It could be your regression suite or smoke suite. Then the results will be delivered to your project team. Thus, if there is a CI break, the team will be notified instantly.
👁️🗨️ How to integrate?
Now, when the process of continuous integration is clear, we will see how we can integrate maven and Jenkins with selenium.
👉Prerequisites
First of all, you need to have Jenkins installed in your system to proceed with continuous integration.
📌 Install Jenkins — https://jenkins.io/download/
📌 To verify the Jenkins version that you have installed
Execute below two commands on the command prompt to verify the Jenkins version
👉 cd <Jenkins installation folder path>
👉 java -jar jenkins.war - -version
As you can see the Jenkins version installed is 2.176.1
📌 To start Jenkins server
🌟 How to create a maven build job?
In order to create the first maven job, you need to log on to your Jenkins dashboard by giving credentials specified during the installation. Firstly, you need to navigate to the hosted path. Usually, it will be hosted on the localhost at http://localhost:8080.
After giving the credentials, you will be navigated to Jenkins dashboard.
👉 Configurations in order to run the first Maven build
- Set JDK Path
📌Go to Manage Jenkins →Global Tool Configuration →Add JDK →Add JDK location against JAVA_HOME
2. Add Maven
⚠️Don’t forget to check “install automatically” check box and save the configurations
3. Install Maven Integration plugin
📌Go to Manage Jenkins →Manage Plugins→Search Maven Integration →Install without restart
🌟 Let’s get started…
Step 1: Select New Item on Jenkins dashboard
Step 2: Enter a valid name and select Maven Project, then click on OK
Step 3: The page you will be taken to from the previous step is where you specify the job configurations. Jenkins understands Maven pom files and project structures and can use the information gleaned from the pom file to reduce the work you need to do to set up your project. On this configuartion page, specify your POM.xml file path.
Let us now specify the POM.xml file path in configuration page
📌 Go to Build and give POM.xml file path for Root POM
📌 Enter ‘test’ into Goals and options to execute a Maven test of your project. These goals can be set according to the tasks that you need to perform
📌 Check “Resolve Dependencies during Pom parsing” which are available in advanced options
Step 4: After apply and save above configurations, you will be taken to project overview page. Here’s the view of the project including its build history
Step 5: Click on “Build Now” to start building the Maven project
Step 6: The progress of the build will be appeared in build history area. If you click on the build number (As I am initially building it is #1), you will be taken to a page with overview of the status of build
Step 7: Once you click on console output, you will be able to see the status of the build at the end of the log. This will be beneficial in examining the results of the job in detail.
How do we identify the status of the build? 💭
As you can see in the above image, S represents status of the build and W represents weather report showing aggregated status of recent builds.
📌 White circle: Not built
📌 Red circle: Failed
📌 Blue circle: Success
📌 Sun: All the builds were successful
📌 Other weather icons will be displayed according to the record of multiple number of successful builds out of all.
This is how we execute a Maven build using Jenkins. I hope you have understood the things that we have discussed in this article.