Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running Selenium Cucumber Tests in Jenkins

DZone's Guide to

Running Selenium Cucumber Tests in Jenkins

How to configure and run Selenium and Cucumber tests in Jenkins on a linux server.

· DevOps Zone
Free Resource

In response to accelerated release cycles, a new set of testing capabilities is now required to deliver quality at speed. This is why there is a shake-up in the testing tools landscape—and a new leader has emerged in the just released Gartner Magic Quadrant for Software Test Automation.

This article shows how to configure and run Selenium (+ Cucumber) Tests in Jenkins. Before we dive into more details we have to have Jenkins installed in a server. Here is a quick way to setup Jenkins in a linux server.

OK all done, lets go though with the steps,

Step 1

First you need to install google chrome. This is called as chrome in headless mode. Because you really can't see the chrome window when you are running tests in Jenkins.

wget -qO - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -  
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'  
sudo apt-get update  
sudo apt-get install google-chrome-stable 

Step 2

Then install xvfb. OK what is this xvfb ?

Based on Wikipedia:

"Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in memory without showing any screen output. From the point of view of the client, it acts exactly like any other X display server, serving requests and sending events and errors as appropriate. However, no output is shown. This virtual server does not require the computer it is running on to have a screen or any input device. Only a network layer is necessary."

sudo apt-get install xvfb  

Then start xvfb

 Xvfb :1 -screen 5 1024x768x8 &

Step 3

OK , server changes are done. Now its time to move into Jenkins configurations.

First install this plugin, (Jenkins -> Manage Jenkins --> Manage Plugins)

Why do you we need this ?

This plugin allows Jenkins to show Selenium + cucumber results as a graph with screenshots.

So in order to generate graphs this plugin need the report.json file that generated from Selenium + cucumber.

 @RunWith(Cucumber.class)  
 @Cucumber.Options(glue = {"classpath:com/rd/uat"}, strict = true, format = {  
     "pretty", "html:target/cukes", "json:target/cukes/report.json", "junit:target/cukes/junit.xml"})  
 public class RunCukes {  
 }  

Here is the plugin configuration in Jenkins.

Create Jenkins Job --> Then add this as "Post build Step"












Step 4

Add following environment variable to Jenkins. (Jenkins --> Manage Jenkins --> Configure System)

 DISPLAY=:1.5  

OK We just configure Jenkins to run selenium and Cucumber Tests.

Now run the Jenkins job and check the cucumber reports. :)

Here are some sample reports,







Recently published Gartner Magic Quadrant Report for Software Test Automation provides an objective benchmark of all test automation solutions based on industry surveys, customer inquiries, product evaluations, and more. 

Topics:
java ,selenium ,cucumber ,jenkins ,testing ,web dev

Published at DZone with permission of Rajith Delantha. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}