The background
There’s this app we’re doing at Aenima that has a pretty large test suite. It’s nothing to brag about in the Ruby community, but here’s the problem: there are a few things covered with Selenium tests (that is, Cucumber tests ran in Selenium environment). Only the Javascript stuff that we cannot otherwise tests, as we’re not big fans of C{u|e}lerity. These Selenium-driven scenarios run great on our development boxes, but recently we have set up Integrity (actually Strzałek did it) on our internal development server for some Continuous Integration goodness.
Having Continuous Integration was a must: the test suite grew so large that a complete run (RSpec + Cucumber) takes from 20 to 40 minutes on our laptops, so it was natural that the frequency of running full test suite dropped considerably within the team, which of course increases the risk of regressions.
Anyway, the dev/CI server is of course headless, no display nor X, so for some time the Cucumber tests were ran with -selenium parameter, but we all knew it was a temporary workaround (I can’t even call that a “solution”). The CI server had to get a running Firefox-Selenium stack.
It was a natural choice to go with Xvfb, the only problem remaining was setting it up and building the rest of the stack on top of it. The man responsible for administration of the dev server, Imanel, has installed Gentoo on it (despite being a Gentoo-fanboy he’s a great guy). Something I can sympathize with, considering my (and not only mine) experience with Ubuntu Server. But still if something can be done in a simple way on most of the distros, it probably cannot be done simply in Gentoo.
Installing Xvfb on Gentoo
Xvfb is basically a part of Xorg system and installing it on a display-less server is something like “installing X without X”. For that I needed some ebuild and USE-flag magic. I’ve copied (with a slight version bump to avoid collision) the latest Xorg ebuild from portage directory that was considered stable on x86, xorg-server-1.7.6.ebuild
And here are two lines the ebuild I had to change (coming from this thread Gentoo Forums) in unified diff format:
And now installing Xvfb-exclusive X was as simple as running
Big thanks to Imanel for reviewing the ebuild, building the digest and making it click.
Running Cucumber-Selenium-Firefox trio under Xvfb
To run Xvfb and have all X-demanding applications run within it, issue these two commands:
And now everything that needs X — including Firefox — will run seamlessly. There are some scrolling/visibility issues with Selenium, that’s why I’ve allocated a larger vertical size for the Xvfb display.
And… that’s it! Withing the same screen session you can just run your Cucumber tests and see the selenium ones running and passing (preferably!). Xvfb can even let you make some screenshots of Firefox as the Selenium tests are running, but I haven’t set that up yet. I’ll probably be lazy and wait for Hubert to crack this nut.
To make it roll with Integrity, wrap the two lines above in a bash script (not ruby script, as the “&” operand won’t work) and have it ran right before the Cucumber suite itself.
Credit for the idea, inspiration and relevant bash lines goes to Hubert Łępicki, to be more specific — a blog post about setting great Rails test stack
Integrating it with multi-project Integrity
Every project added to Integrity should have its own instance of Xvfb, running on separate display, to avoid collision.
…rest is coming soon.