Selenium Integration with Jenkins

In this post we will discuss about following points:
  • What is Continuous Integration?
  • What is Jenkins
  • Advantages of Jenkins
  • Other CI tools
  • Complete Jenkins installation Process
What is Continuous Integration?
Continuous Integration is a development practice in which the Automation Testers are required to commit changes to the source code in a shared repository several times a day or more frequently. Every commit made in the repository is then built. This allows the teams to detect the problems early. Continuous Integration is the most important part of DevOps that is used to integrate various DevOps stages. Jenkins is the most famous Continuous Integration tool.

What is Jenkins?
Jenkins is an open source automation tool written in Java with plugins built for Continuous Integration purpose. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies. Jenkins integrates development life-cycle processes of all kinds, including build, document, test, package, stage, deploy, static analysis and much more. Jenkins achieves Continuous Integration with the help of plugins. Plugins allows the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example: Git, Maven, HTML publisher etc.

  • Advantages of Jenkins include:
  • It is an open source tool with great community support.
  • It is easy to install.
  • It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and share with the community.
  • It is built with Java and hence, it is portable to all the major platforms.
Apart from Jenkins, we have many more tools in the market such as:
  • Anthill
  • Bamboo
  • Cruise Control
  • Team City
Complete Jenkins Installation Process

1. Download the WAR file from 

2. Start the Jenkins using below commands:
>C:\Users\Hitendra>java -jar <Path of WAR file> --httpPort=8082
Default port is 8080, no need to specify port if your jenkins running on 8080 port

Press Enter

3. Browse to http://localhost:8080 (or whichever port you configured for Jenkins when installing it) and wait until the Unlock Jenkins page appears.

4.  From the Jenkins console log output, copy the automatically-generated alphanumeric password from the cmd or from given path.

5. On the Unlock Jenkins page, paste this password into the Administrator password field and click Continue.

6. You can install either the suggested plugins or selected plugins you choose. To keep it simple, we will install the suggested plugins.

7. Wait until the plugins are completely installed.
8. The next thing we should do is create an admin user for Jenkins. Put in your details and click “Save and Continue”.

9. Click “Save and Finish” to complete the Jenkins installation.
10. Now, click “Start using Jenkins” to start Jenkins.
11. Finally, here is the default Jenkins page.
Please refer below YouTube videos to understand the Different Configurations on Jenkins
  • Demo 1: Create a batch file and run on Jenkins (Integration of Eclipse Java Project + Jenkins)
  • Steps to create the batch file 
set projectLocation=D:\Workspace_Eclipse\TestNGJenkinsDemo
cd %projectLocation%
set classpath=%projectLocation%\bin;%projectLocation%\lib\*
java org.testng.TestNG %projectLocation%\testng.xml

Save this file with extension (.bat).
Please follow below video on how to use this command in Jenkins

Demo2 : Installation of different plugins and Integration of (Selenium + Maven + Jenkins) and Selenium + Maven + GitHub + Jenkins Integration with Parameters

Demo3 : Selenium + Maven + GitHub + Jenkins + TestNG Report + Extent Report + Email +Email with Attachment + Schedule Jobs
In this video, we will discuss about following things.
1. How to generate HTML report in Jenkins
2. How to generate Extent report in Jenkins
3. How to send email
4. How to send email with an attachment
5. How to run job periodically in Jenkins

Sample Email Body Template:
Hi Team,
Please find the below Automation Testing Results for Project: <b>$PROJECT_NAME</b>.
<b>Project Name:</b> $PROJECT_NAME 
<b>Build#</b>: $BUILD_NUMBER
<b>Build Status</b>: $BUILD_STATUS.<br/>
Check <a href='http://localhost:8082/job/Demo4/ws/ExtentDemo/test-output/ExtentReport/MyReport.html'>Extent Report</a> to view full results.<br/>
Please find below <b>Colsole Logs</b> for your reference<br/>
<pre style='line-height: 22px; display: block; color: #333; font-family: Monaco,Menlo,Consolas,"Courier New",monospace; padding: 10.5px; margin: 0 0 11px; font-size: 13px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0,0,0,.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;'>
${BUILD_LOG, maxLines=500, escapeHtml=true}
Thank You

Please refer below YouTube Video for complete understanding:

Demo4 : Add logo in extent report and attach screen shot for failed test case-