Inspect Network-Traffic in Capybara with Poltergeist

Stefan Hoffmann
<pretty/code>
Published in
2 min readDec 14, 2015

Ever tested a page with a lot of AJAX-Actions and encountered some strange bugs? If you are using Poltergeist there are good news.

Poltergeist is a driver for Capybara that runs your tests in PhantomJS.

Let’s say you have a page with a button which sends an AJAX-Request, but something didn’t work.
If you are in the browser the first thing you’ll do is to open the DevTools and look for errors in the console and look in the Network-Tab to inspect the Request.

But what do you do if you are in an Capybara Test?
If you are using Poltergeist as driver you can simply do:

page.driver.network_traffic

And you will get all the informations you would see in the Network-Tab of your browser.

To use Poltergeist as JS-Driver, install the poltergeist- and the phantomjs-Gems and configure it for Capybara:

options = {}
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, options)
end
Capybara.javascript_driver = :poltergeist

--

--