Behat, Selenium and Vagrant
Don’t run Selenium server in your Vagrant box, run it in your host.
On one of my laptops I have a Vagrant box which is a replica of a live CentOS web server (provisioned via Ansible), and there is where all my code resides and naturally where I run my tests from also, whilst my host is completely clean (14.04 Ubuntu and SublimeText as IDE).
Just before getting to the steps, I don’t know whether you read already or not the Behat And Selenium in Vagrant article, but it depicts how to run the tests inside Vagrant, by having to install firefox, xvfb and headless jre in your Vagrant box. Well, I don’t think it’s the right way to do it. **Leave your box intact** And the reason is that, unless you run in a complete CLI environment, most certainly is that your host has almost everything you need to run Selenium there (maybe missing JRE).
1. Download Selenium on my host machine from their official page
2. Adjust my project’s behat.yml parameters for Selenium to call to my host:
selenium2: wd_host: HOST.IP.HERE.PLEASE:4444/wd/hub capabilities: browser: firefox version: ANY
so for example, you’d end up with something like:
3. Start Selenium server inside your host:
java -jar /path/to/selenium-server-standalone-2.52.0.jar
4. Run your tests inside vagrant:
cd /my/project/path && vendor/bin/behat
5. See Firefox opening and tests being executed.
And there you go. No need to overcomplicate your Vagrant box, having to install additional tools, setting up X11 forward, and so on.