Table of Contents
Benefits of Acceptance Testing
Acceptance Testing Framework - Capybara/Poltergeist
As useful as these types of tests can be, getting acceptance tests running on a CI server can be tricky and can add significant overhead to testing time. We use Capybara to write acceptance tests because of its intuitive DSL, integration with Rails, and the ability to integrate with different web-drivers. We use Poltergeist as the web-driver for Capybara because it allows us to use PhantomJS on our CI server which doesn’t require an X server to run tests against a browser. Poltergeist is solely dependent on PhantomJS and will require any machine running your acceptance tests to have PhantomJS available.
Providing the PhantomJS Dependency
Before we can start using a headless browser in our acceptance testing framework, we’ll first need to provide the PhantomJS dependency for our system. Since there are no official packages for PhantomJS, we need to build it from source on our target operating system, and then package it into the format we need. While there are no official packages (deb, rpm, etc.) for PhantomJS, there is an official static build available on the PhantomJS website. We also have a packagecloud repository containing PhantomJS packages for different operating systems. We won’t go over the steps on how to build the package from source, but you can take a look at this post and this post to get a better idea on how to build packages.
Once we have the package for PhantomJS, we can push it up to our packagecloud repository.
package_cloud push armando/phantomjs ./phantomjs_2.0.0_amd64.deb
Now all we have to do is install the repository onto our CI server using the bash scripts provided by packagecloud.
curl -s https://packagecloud.io/install/repositories/armando/phantomjs/script.deb.sh | sudo bash
And install the package during the CI setup process:
sudo apt-get install phantomjs
scenario (which is an alias for
it in the Capybara DSL):
By default, Capybara uses
:js => true or
selenium web-driver without any further configuration. To override the default driver to use Poltergeist, set the following value in your spec helper or wherever you configure your tests:
Writing acceptance tests is a crucial part of the development process. Modern web applications often require the loading and manipulation of elements into a DOM, so enabling a full DOM environment when running your acceptance tests is critical to catching potential user facing bugs before they hit production. Using a headless browser like PhantomJS enables us to test end-to-end features without bogging down our testing pipeline with extraneous dependencies.