Automate Acceptance Tests with Hound
Manual acceptance tests are powerful, but they are also cumbersome to run. We performed tests in this chapter that took several minutes to execute, at a minimum, and were prone to error if we missed any of the steps. We can improve on manual acceptance tests by automating them.
Automated acceptance tests are compelling because they let us run hundreds or thousands of acceptance tests without a person being involved. If each acceptance test takes one minute to execute (a very conservative estimate), one thousand tests would take over 16 hours of non-stop testing! It would be extremely costly to cover an extensive application with manual acceptance tests fully. Automated acceptance tests improve on this by being able to run on a dedicated server without a person involved and allowing the fast setup of a test scenario. A thousand automated acceptance tests may run in an hour or less, which is a reasonable amount of time.
In this section, we’ll leverage WebDriver and Hound to write automated acceptance tests. We’ll write tests that feel like standard ExUnit tests but are full-stack acceptance tests. We will not port the manual tests we ran earlier to automated tests. It is possible to port those tests over, but we will stick with more straightforward tests for this section.
The power of WebDriver and Hound
WebDriver is an interface to automate browsers. We can use a WebDriver implementation to build an automated test suite against a real browser. Many different types of WebDrivers can control a variety of major browsers. We’ll be using ChromeDriver to write automation tests against Chrome.
Most likely, we will not use WebDriver directly. Instead, we’ll use libraries that integrate with WebDriver to control a page and perform assertions against that page’s content and behavior. This gives us the ability to write full-featured browser tests in our favorite language. Of course, we’ll be writing our tests in Elixir, but a QA engineer could just as easily write these tests in a different, more familiar language. It’s important to write tests that both a core engineering team and a QA engineering team can maintain because members of each team will often update acceptance tests.
Hound is an Elixir library to write WebDriver-powered tests. Writing Hound tests is very similar to writing a normal ExUnit test—we are just controlling a real browser rather than an Elixir application. An advantage to writing automation tests in the same place we have written other tests is that we will use the same factories and helpers we previously built.
Hound is a bit trickier to set up than other libraries we’ve used, so we’ll walk through all of the setup steps next.
The first step to getting Hound set up is downloading and setting up ChromeDriver. Hound will be configured to use ChromeDriver, so it must be running properly. We should obtain the latest stable release of ChromeDriver. We need to download the appropriate version for our system and unzip it onto our computer somewhere. It’s easy to get ChromeDriver running once it’s downloaded. We will just start it like we would start a normal executable: