UPDATE (May 2019): The video below has been updated and expanded. Check it out!
Behaviour Driven Development (or BDD) ensures everyone has the same understanding of how an application should work and gives you a clear indication when a feature is finished. In general, any test-automation dramatically speeds up acceptance and regression testing.
Plus, it feels like magic.
Unfortunately, getting started can be tough. You need a browser, a testing framework like Cucumber, a web driver like Selenium, and something like Capybara to glue it all together (which requires Ruby).
Here’s a quick and easy way to set up a BDD environment using Docker and standalone Selenium containers. In the video below we create a browser container, connect to it with VNC so we can see what’s happening, then create another container to run Ruby/Capybara and then we test Google to make sure that we see the word “dog” when we search for “puppies”.
To begin, clone this repository from a terminal like so:
git clone email@example.com:peterkappus/selenium-cucumber-docker.git
Now move into the directory you just cloned…
Start the two containers (one for running ruby, and one with the browser). We specify that we want a bash session (so we can run cucumber interactively), and this container specifies the browser container as a dependency so it will start automagically.
docker-compose run ruby bash
Now you can see into the browser container by using VNC to connect:
This should open a VNC viewer and show you an empty Ubuntu desktop.
Returning to the original terminal window, we should have a bash session where we can start cucumber:
Looking at the VNC window, we’ll see a browser open and perform a Google search, and then close. In the Ruby container, we can see the tests running and see the results.
We can now extend this by writing tests in our “feature” folder and step definitions in our “features/step_definitions” folder. The repo above includes a few generic step definitions for seeing things and clicking on things. You’ll no doubt want to write your own but this will get you started.
When you’ve finished testing, you can exit the ruby container like so:
And finally stop both containers by running this from the host:
I hope this helps you to get started exploring test automation and BDD and makes it easier to standardise your test environment among your development team.
Let me know how it works for you!