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).

Right. In order to run my Behat/Mink Selenium tests and see the results in my host browser for a Phalcon PHP project, this is what I ended up doing

Remember to tag the scenario you want to test with Selenium, with @javascript, eg.:

@javascript
Scenario: Accessing the registration page and seeing the registration form inputs
Given I am on "/"
When I follow "Sign Up"
And I am on "/sign-up2
Then I should see a "email" "input" type "text"
And I should see a "firstName" "input" type "text"
And I should see a "lastName" "input" type "text"
And I should see a "password" "input" type "password"
And I should see a "confirmPassword" "input" type "password"
And I should see a "howFind" "select"
And I should see a "termsText" "textfield"
And I should see a "terms" "input" type "checkbox"
And I should see a "optOut" "input" type "checkbox"

And there you go. No need to overcomplicate your Vagrant box, having to install additional tools, setting up X11 forward, and so on.

English is my third language, please feel free to embrace my curious grammar or help me improve it as Yoda would.I don't care what, when, how or from whom I learn. I just care that I learn. - Alex Lawrence-BerkeleyNothing will work, unless you do. - Maya Angelou