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”:

xvfbJenkins

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:
xvfbInstall

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.

xvfbJob

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.

xvfbjob2

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.

7 thoughts to “Run Headless Selenium Tests From Jenkins

  • Preetham

    Hi Marc,

    I have set up the xvfb plugin in jenkins. When I give the build tests are being skipped with below console display

    Running TestSuite
    Tests run: 78, Failures: 12, Errors: 0, Skipped: 66, Time elapsed: 3.152 sec <<< FAILURE!

    Results :

    Failed tests:
    setup(com.sothebys.en.tests.Individual_Page_Tests.KeyCloak)
    close(com.sothebys.en.tests.Individual_Page_Tests.KeyCloak)
    setup(com.sothebys.en.tests.Individual_Page_Tests.Login)
    close(com.sothebys.en.tests.Individual_Page_Tests.Login)
    setup(com.sothebys.en.tests.Individual_Page_Tests.HomePage)
    close(com.sothebys.en.tests.Individual_Page_Tests.HomePage)
    setup(com.sothebys.en.tests.Individual_Page_Tests.ArtistPage)
    close(com.sothebys.en.tests.Individual_Page_Tests.ArtistPage)
    setup(com.sothebys.en.tests.Individual_Page_Tests.ObjectPage)
    close(com.sothebys.en.tests.Individual_Page_Tests.ObjectPage)
    setup(com.sothebys.en.tests.Individual_Page_Tests.ImportExportPage)
    close(com.sothebys.en.tests.Individual_Page_Tests.ImportExportPage)

    And My scripts run on firefox and chrome . Does both the browsers need to be installed on linux?

    Thanks in Advance

    Reply
  • Marco Corona

    Hi Preetham,

    Yes, if you are running tests on different browsers then you would need to install all drivers for the browsers that you need. In this case, you would need to install and run chrome in a headless fashion, which looks to be simple now with versions 59+ (https://developers.google.com/web/updates/2017/04/headless-chrome)

    Reply
  • Pedro Fernández Montesino

    Marco,

    I’m trying to test a maven proyect with Jenkins/Selenium/Chromedriver/Xvfb. I’ve followed your steps without luck.

    I’ve tried with export DISPLAY=:1208 and with export DISPLAY=:99 with the same result.

    This is the console output from Jenkins:

    No changes for https://slsvn.indra.es/IBE/branches/SeleniumQA/ChromeQA since the previous build
    Xvfb starting$ /usr/bin//Xvfb :1208 -fbdir /home/adminam/.jenkins/xvfb-23-1588636031041454648.fbdir
    [Prueba Selenium] $ /bin/sh -xe /apps/apache-tomcat-7.0.73/temp/hudson3609721560214169386.sh
    + export DISPLAY=:1208
    + DISPLAY=:1208
    [Prueba Selenium] $ /apps/apache-maven-3.3.9/bin/mvn test
    [INFO] Scanning for projects…
    [INFO]
    [INFO] ————————————————————————
    [INFO] Building PruebasRegresionLotChrome 0.0.1-SNAPSHOT
    [INFO] ————————————————————————



    [INFO] ——————————————————-
    [INFO] T E S T S
    [INFO] ——————————————————-
    [INFO] Running es.indra.qa.PruebasRegresionLotChrome.TestRetrievePnrChrome
    Starting ChromeDriver 2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351) on port 17692
    Only local connections are allowed.
    [ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.957 s <<< FAILURE! – in es.indra.qa.PruebasRegresionLotChrome.TestRetrievePnrChrome
    [ERROR] testRecuperarPnr(es.indra.qa.PruebasRegresionLotChrome.TestRetrievePnrChrome) Time elapsed: 1.823 s <<< ERROR!
    org.openqa.selenium.WebDriverException:
    unknown error: cannot find Chrome binary
    (Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 3.10.0-327.36.3.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 54 milliseconds
    Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
    System info: host: 'EALLDW02', ip: '10.29.65.20', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.36.3.el7.x86_64', java.version: '1.8.0_111'
    Driver info: driver.version: ChromeDriver
    at es.indra.qa.PruebasRegresionLotChrome.TestRetrievePnrChrome.setUp(TestRetrievePnrChrome.java:18)

    [ERROR] testRecuperarPnr(es.indra.qa.PruebasRegresionLotChrome.TestRetrievePnrChrome) Time elapsed: 1.824 s << [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
    Build step ‘Invoke top-level Maven targets’ marked build as failure
    Xvfb stopping
    unlink: No such file or directory
    unlink /home/adminam/.jenkins/xvfb-23-1588636031041454648.fbdir/Xvfb_screen0 failed, Invalid argumentFinished: FAILURE

    Can you help me with this?

    Reply
  • dude

    Sir!
    Thanks for a short and easy description. Saved me loads of time.

    /sys/john

    Reply
  • sonal

    Hi,

    I have followed the same Steps as written above. I am trying to run the selenium tests from Jenkins.
    Jenkins is setup on EC2
    > I have set Manage Jenkins” –> “Configure System” –> “Xvfb Installation
    > Xvfb is installed in the jenkins server and command Xvfb :0 >& /dev/null & hows me the id.
    > In the Jenkins job I have checked – Start Xvfb before the build, and shut it down after.
    It has the Display name as 0
    > I have set the DISPLAY variable in Manage Jenkins -> Configure System -> Global Properties -> Environment Variables

    now when I run the job in Jenkins I get below error
    org.openqa.selenium.WebDriverException:
    Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: LINUX

    Please help to resolve this issue. I have been trying so many solutions since last 2 days but I am stuck here.

    Reply
  • Mayur

    Hi Mark,
    I am running test on mac. I have written script in sikuli to upload file on mac, but i am not able to run this script on jenkins. I am able to run it from locally. Can u help me in this?

    Reply
  • Pingback: Top 10 Coveros Blogs of 2019 - Coveros

Leave a comment

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

X