Automate Selenium testing with Jenkins

30 / Jul / 2016 by Navjot Singh 3 comments

Selenium is a tool widely used for automating testing of web applications. One step ahead, integrating the selenium with Jenkins takes it to the next level.
In this blog, we would be configuring Jenkins to run selenium test cases on an ubuntu environment.


Scenario: Configure Jenkins to perform Selenium test cases with one click.

I am using Amazon EC2 server which has Ubuntu running on it and has Jenkins server installed on it. Since most of the test cases are running on firefox in my case, so I have installed firefox on the server.


  1. Install Maven Integration plugin: I am considering this plugin since most of the developers use Maven as a build tool for running their test cases.
  2. Install Xvnc plugin: This plugin is required as it creates a web browser instance in memory where all the test cases run.
  3. GIT plugin: I am assuming the code of the test cases is pushed on git, so we would need this plugin to pull the code.

Let’s create a Jenkins job for our scenario as below:

  1. Login into your Jenkins server and create a new “Maven Project” in Jenkins console.
  2. Make the build parameterized if the test cases parameters to be passed to them.
  3. Provide your git repository and branch/tag in after selecting git under “Source Code Management”.
  4. Under “build triggers”, select “Build whenever a SNAPSHOT dependency is built” which tells Jenkins to check the snapshot dependencies from the <dependency> element in the POM, as well as <plugin>s and <extension>s used in POMs.
  5. Under “Build environments”, select “Run Xvnc during build”. This will provide an X display for the web browser to run the test cases.
  6. Under “Build”, provide the path of pom.xml and pass the Goals such as clean, test etc with your profile by using “-P” if you are using multiple profiles in test cases. If your build is parameterized, the options will be passed with goals and profile with “-D”.
  7. In “Post Build” steps, the report generated by Selenium can either be mailed or served from the server using HTTP or can be pushed to AWS S3. I found the last option better as AWS S3 is cheap and provide unlimited storage. After uploading the report on AWS S3, the report can be deleted from the server and can be shared using AWS S3 URL so we do not need to serve the report from the server. To upload the report to AWS S3 use “ Jenkins S3 publisher plugin” plugin and provide the AWS S3 bucket path where the reports would be uploaded. The report URL from S3 could be shared over mail or can be printed  in the Jenkins’ logs.
  8. In case, we need to analyze previous reports, another Jenkins job can be created which can list the desired number of links to the previous reports uploaded on AWS S3.
  9. Now, anyone can run the selenium test cases with a single click by accessing the Jenkins’ job.

For more customisation and as per the needs of the developer, the job can be configured to run on multiple web browsers and it can be passed as a parameter to the Jenkins’ job.


comments (3)

  1. Rohit Vatta

    I am getting following error on build now against my nightwatch tests configured as job over Jenkins:

    Error retrieving a new session from the selenium server

    Connection refused! Is selenium server started?
    { Error: socket hang up
    at createHangUpError (_http_client.js:254:15)
    at Socket.socketCloseListener (_http_client.js:286:23)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:498:12) code: ‘ECONNRESET’ }

    npm ERR! Test failed. See above for more details.
    Build step ‘Execute shell’ marked build as failure
    Finished: FAILURE

    Can you please advise how to resolve this?


    Rohit | 9871998357

  2. Vinay Kumar M

    Hello Navjot, Exactly I’m looking for same, that you have given in above. Can you please tell what can be src/test/java test file that will work in Ec2 instance, Because I’m using

    package MavenDemo;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.Test;

    public class testFacebook {

    public void TestFireFox(){

    WebDriver driver=new FirefoxDriver();





    above file, for which testing.xml is generated in Eclipse. Its working fibe in eclipse if create a build, but it is failing in ec2 instance. Hope issue is with firefox driver instance,I haven’t installed any firefox in ec2, But how to deal same with Ec2-instance. please share if any sample you have.

    Thanks in Advance

    1. Navjot

      I believe the system on which eclipse is installed in Windows where firefox is already installed.

      Which AMI are you using for ec2? Windows or Linux. If Windows, install firefox as you did it on your system and for linux do following:
      For ubuntu: sudo apt-get update;sudo apt-get install firefox -y
      For centos: sudo yum update, sudo yum install firefox -y


Leave a Reply

Your email address will not be published. Required fields are marked *