BLOG

Running Selenium Tests in Headless Mode on Jenkins

by Sysco LABS Quality Engineering 14 September 2015

Currently we are working with a web application which has a front-end test suite written using selenium and Cucumber.  Initially we used to manually run these on our local machines. But later we planned to run these nightly on a build server which is on AmazonEC2 (Ubuntu).

The main challenge was to setup the environment to run Google Chrome in headless mode to run the tests. In this article I will explain the environment setup as well as configuring Jenkins to run the selenium tests.

1. Install Chrome

 wget -q -O – 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

2. Install Xvfb

Xvfb is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.

 sudo apt-get install xvfb

3. Start Xvfb

Xvfb :1 -screen 5 1024x768x8 &

4. In Jenkins environment variables set following variable

DISPLAY=:1.5

Now you should be able to run tests which uses Chrome web driver with Jenkins. To show Cucumber reports you can use this Jenkins plugin.

 

Configuring Jenkins to run the reports

This plugin requires Cucumber output in Json format. To enable this you have need cucumber options like this in your runner class.

@RunWith(Cucumber.class)

@CucumberOptions(format = {“pretty”, “html:target/cucumber-htmlreport”,json:target/cucumber.json},

glue = {“com.leapset.test.www.reportng.framework.tests.bdt”},

tags = {“@RngLogin”,“~@manual”})

public class RunReportsNgLoginTests {}

 

After installing this plugin in Jenkins create a Jenkins job to run front end tests. In the post build steps add step named Publish cucumber results as a report.

1

 

Once you run the job you will be able to view the Jenkins reports via Jenkins.

 

2

3

Article by: Prabhath Pathirana, Software Engineer- Leapset Engineering

 

3 Comments for “Running Selenium Tests in Headless Mode on Jenkins”

  1. Takumi says:

    (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at test_harness.pl line 100.BEGIN faield compilation aborted at test_harness.pl line 100. So i just modify use POE to cpan POE then i got Bareword KERNEL not allowed while strict subs in use at ./test_harness.pl line 259.Bareword HEAP not allowed while strict subs in use at ./test_harness.pl line 259.Global symbol $poe_kernel requires explicit package name at ./test_harness.pl line 463.Execution of ./test_harness.pl aborted due to compilation errors. What can i do for this? Thanks Eric

  2. Very nice post and straight to the point. I don’t know if this is really the best place to ask but do you folks have any ideea where to employ some professional writers? Thank you 🙂

  3. Wow. That is so elegant and logical and clearly explained. Brilliantly goes through what could be a complex process and makes it obvious.

Leave a Comment

Tags