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.
- 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.
- Install Xvnc plugin: This plugin is required as it creates a web browser instance in memory where all the test cases run.
- 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:
- Login into your Jenkins server and create a new “Maven Project” in Jenkins console.
- Make the build parameterized if the test cases parameters to be passed to them.
- Provide your git repository and branch/tag in after selecting git under “Source Code Management”.
- 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.
- Under “Build environments”, select “Run Xvnc during build”. This will provide an X display for the web browser to run the test cases.
- 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”.
- 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.
- 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.
- 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.