4

I've written some functional tests for my Grails app using Geb. I've configured my tests identically to this example project, which allows you to specify a list of browsers that the tests may be run against.

The tests pass when I run them locally against Firefox. However, they fail if I run them on Jenkins, because Firefox cannot run in headless mode. A common solutions for this problem seems to be to use XVFB to emulate a display, so that Firefox can run on a headless machine. I've successfully installed XVFB on the Jenkins machine, but am not sure what additional configuration is required in order to get XVFB working with the Jenkins job that runs the functional tests?

There is an XVFB Jenkins plugin available, should I use this or is there another approach that people have been successful with?

Dónal
  • 185,044
  • 174
  • 569
  • 824

5 Answers5

0

I don't really remember why we didn't go with the Xvfb Jenkins plugin but this is how we have it set up:

  • Have Xvfb running as a service on your slaves providing a certain display, say 99.
  • Set an env variable to let your browser used for testing know which display to attach to, i.e. DISPLAY=:99 as a config step of your job executed before tests, we're using EnvInject Plugin for that
erdi
  • 6,944
  • 18
  • 28
  • 2
    I've changed the focus of my question a bit since your answer. Would you mind providing some details about how you configure the Jenkins job that runs the Geb tests to use XVFB? – Dónal May 27 '14 at 13:39
0

There is an XVFB Jenkins plugin available, should I use this or is there another approach that people have been successful with?

We are using this plugin to run our geb tests for grails application. We only have to did a little configuration as described at plugin site ie. in "Jenkins configuration" there is defined Xvfb instalation and on "Job configuration" option "Start Xvfb before the build, and shut it down after" is checked.

Our Jenkins is running on Debian so we have to install xvfb package (and also ttf-dejavu)

sudo apt-get install ttf-dejavu xvfb
Marcin Armatys
  • 599
  • 9
  • 25
0

I installed the Jenkins plugins as follows;

Go to Manage Jenkins > Manage plugins and install Xvfb plugin

Then, configure the plugin;

Manage Jenkins > “Configure System” or “Global Tool Configuration” > Scroll down to Xvfb installation and give it a default name and executable path (can be found using "which Xvfb" in a terminal). Now install Firefox on the box: yum install firefox

Finally, configure the project in question by checking the new "Start Xvfb before the build, and shut it down after" checkbox and run the geb tests with Firefox as the chosen browser.

dre
  • 1,027
  • 1
  • 11
  • 31
0

What we do and are happy with is not Xvfb but using PhantomJS (PJS) on the Jenkins server in combination with Geb's screenshot (report) feature so as to document important test steps as well as failures. Depending on how complex your pages are you can also use HtmlUnit + activated JavaScript instead of PJS. The downside of Xvfb is that you really need to install GUI browsers on the usually headless Jenkins server, boot them up and shut them down cleanly etc. I would not go that way if I were you. Another advantage of PJS and HtmlUnit is that you can also run the tests locally on a developer machine without browser windows interfering with you IDE all the time. This is a great add-on to local tests in other browsers such as Chrome, FF, IE.

Update: You should have different Maven profiles or at least different geb.env variables set in your build so as to decide in GebConfig which browser to use for testing. This way you are really flexible. We use this to switch between normal browsers, headless browsers and cloud services such as TestChameleon, BrowserStack or SauceLabs.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
0

I use a selenium-grid deployed with docker container. See https://hub.docker.com/r/selenium/hub/ and https://github.com/SeleniumHQ/docker-selenium

So you don't have to install firefox, chrome, .... in you jenkins server.

mturra
  • 640
  • 8
  • 14