If you use Vagrant, VirtualBox and Ubuntu to build your Rails apps and you want to test it with Cucumber scenarios, this is the right post for you. By default Vagrant and VirtualBox use Ubuntu without an X server and GUI.
Everything goes well until you need
Selenium WebDriver is flexible and lets you run selenium headless in servers with no display. But in order to run, Selenium needs to launch a browser. If there is no display to the machine, the browsers are not launched. So in order to use selenium, you need to fake a display and let selenium and the browser think they are running in a machine with a display.
Install latest version of Mozilla Firefox:
sudo apt-get install firefox
Since Ubuntu is running without a X server Selenium cannot start Firefox because it requires an X server.
Virtual X server is required to make browsers run normally by making them believe there is a display available, although it doesn’t create any visible windows. Xvfb (X Virtual FrameBuffer) works fine for this. Xvfb lets you run X-Server in machines with no display devices.
Install xvfb on ubuntu:
sudo apt-get install xvfb
Lets run the Xvfb service in a display number which is less likely to clash even if you add a display at a later stage. Display 10 will do fine.
sudo Xvfb :10 -ac
The parameter -ac makes xvfb run with access control off. The server should be running now.
Before you can run a browser, you need to set the environment variable DISPLAY with the display number at which xvfb is running.
Open new tab in terminal and set the DISPLAY variable:
and start mozilla firefox:
Now you run firefox headlessly in Ubuntu, and you can run your cucumber scenarios with
To run your X server automatically, after installing Xvfb, you will need to:
sudo wgetcommand to do that)
sudo chmod a+x /etc/init.d/xvfb
sudo /etc/init.d/xvfb start
sudo /etc/init.d/xvfb stop
This is my way to run firefox headlessly in Virtual box Ubuntu, and to run cucumber scenarios with
References:ruby, rails, vagrant, virtualbox, ubuntu, cucumber, selenium-webdriver