Running Iridium Scripts in Firefox With Jenkins
This article shows you how to configure Iridium, xvbf and Jenkins to run test scripts in Firefox in a headless environment.
Join the DZone community and get the full member experience.Join For Free
It is very common to run Iridium test scripts on a CI server like Jenkins or Bamboo as part of a web application build process. Typically these servers are headless, which is to say that the CI service is run from a terminal that has no graphical capabilities. This presents something of a challenge given that Iridium is running test scripts against graphical web apps.
A common solution is to use PhantomJS. This is a web browser that can be run in headless environments as it never actually displays anything on the screen. PhantomJS is a neat solution, but it does have some subtle issues that you will run into. One that I ran into was the fact that PhantomJS exposes touch events to the web applications it runs, which can in turn trick the apps into thinking they are running on a mobile device. The Ticket Monster JBoss demo application is one example of an application that will switch to mobile mode when run in PhantomJS.
Below is a screenshot of Ticket Monster when run in PhantomJS. Despite the large resolution, we’re still getting the mobile version.
To test applications that don’t quite work as expected in PhantomJS, it is possible to run browsers like Firefox in a headless environment under Linux with xvfb. Xvfb provides a virtual screen that Firefox will render to, without needing a physical screen present to display the output.
Configuring xvfb and Jenkins on a Linux box is pretty easy. To start with, make sure you have xvfb and Firefox installed on your CI server. There are plenty of instructions on how to install these applications, and they will almost certainly be provided with your standard Linux package manager.
Next, install the Xvfb Jenkins plugin. We’ll use this plugin to manage xvfb as builds are started and stopped.
We’ll need to add some global environment variables in order for Firefox to work with xvfb. Click Manage Jenkins -> Configure System, and add a global environment variable called DISPLAY with the value :99. The number 99 is just something we make up, and we’ll use it again when configuring the Iridium Jenkins job.
We then need to add an xvfb installation. Click Manage Jenkins -> Global Tool Configuration, and add an xvfb installation. On my server, the Install automatically option worked fine.
Finally we need to configure the Iridium test build. In this example we’ll be executing the verification example that comes with Iridium by building Iridium from the source code in GitHub.
We give the project a name, and point it to the GitHub project URL.
We define the location of the source code.
We add a trigger to run the test whenever the Git repo is updated.
Then we need to configure xvfb as part of the build. The important fields are Xvfb specific display name, which we set to 99 (just like the DISPLAY environment variable that we defined earlier), and Xvfb screen, which is set to 1920x1080x24 to reflect an averaged sized monitor. I also enable the Log Xvfb output option as it is useful for tracking down any errors that might occur.
For the build section, we start by clearing out any old artifacts.
Then we run Iridium via a Gradle build script. The Switches section contains the follow options:
-DappURLOverride=http://ticketmonster-jdf.rhcloud.com -DtestSource=https://raw.githubusercontent.com/mcasperson/IridiumApplicationTesting/master/examples/22.verification/test.feature -DtestDestination=Firefox -DenableScenarioScreenshots=true -DsaveReportsInHomeDir=false -DphantomJSLoggingLevel=NONE -Dwebdriver.firefox.bin=/usr/bin/iceweasel
The only thing that might stand out here is that I’ve set the Firefox location to /usr/bin/iceweasel, which is just a version of Firefox that is distributed with Debian (the OS that is hosting my Jenkins server).
For the post build actions we save the Cucumber artifacts (log files, screenshots, reports), and parse the JUnit report file called MergedReport.xml.
With this configuration in place, Iridium will run the test script in Firefox (or Iceweasel as the case may be with my Debian server), and the Ticket Monster application presents the full desktop experience.
Published at DZone with permission of Matthew Casperson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.