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

Run Headless Selenium Tests From Jenkins

DZone's Guide to

Run Headless Selenium Tests From Jenkins

This tutorial shows you how to run headless Selenium tests via Jenkins using a centOS machine in a continuous integration environment.

· DevOps Zone ·
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

In a previous blog, I went over how to set up headless tests on a centOS machine; in this blog, I will be going over how to introduce this machine into a continuous integration environment via Jenkins.

The first thing that we need to do is install the Xvfb plugin on the Jenkins instance, which is installed through "Manage Jenkins" --> "Mange Plugins":

Image title

Now that the plugin is installed, we must tell Jenkins where our Xvfb installation is located. This is done through "Manage Jenkins" --> "Configure System" --> "Xvfb Installation". On my centOS machine, Xvfb is located at /usr/bin as seen below:

Image title

The next step in getting our headless tests to run is to go to the job(s) that will be running the headless tests to configure the plugin. For this first and simplest example, it will be assumed only one instance of this test job will be run on the slave that can run headless tests.

Image title

In the above picture, you will see the configuration block for the Xvfb plugin. The first thing we want is to check the box "Start Xvfb before the build, and shut it down after."

The next configuration option to pay attention to is which Xvfb installation you would like to use for this specific job. If you have set it up like above, it will be the "Default" installation.

For the next option, the value "10" is inserted into the "Timeout in seconds" box. This option tells the job to give Xvfb 10 seconds to start up before the job continues. You may want to increase or decrease the timeout depending on how your slave that this job is running on performs.

Next, it is important is to keep the "Xvfb display name offset" at 0. This option is used when you do not explicitly set the display name for Xvfb to run on.

Image title

Finally, before your tests run, it is important to set your DISPLAY variable to the display that Xvfb is started on, so Firefox knows where to look; In this case, it is :99, as seen above.

Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

Topics:
jenkins ,selenium ,integration ,centos ,testing ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}