gpro6g
Last Updated: February 25, 2016
·
5.334K
· afgomez
578855 3794745059411 1045494353 n

Debug your capybara features with Chrome web inspector. Easily!

Poltergeist has the ability to debug your tests using the Chrome web
inspector, but the syntax to do so is a little bit awkward to my taste so I
created a handy method easier to remember and write.

First you need to create a specific capybara driver for debugging in your
spec/spec_helper.rb file.

# spec/spec_helper.rb

# ...
require 'capybara/poltergeist'

Capybara.register_driver :poltergeist_debug do |app|
  Capybara::Poltergeist::Driver.new(app, :inspector => true)
end
# ...

Nice! Now inside your spec/support folder create a file with these lines in
it:

# spec/support/debugit.rb

def debugit( *args, &block )
  it( *args, { driver: :poltergeist_debug, inspector: true }, &block )
end

Now you can use the debugit for test your specs!

# spec/features/random_spec.rb

require 'spec_helper'
describe "Random feature" do
  it "Does't have debugging" do
    # ...
    # This will raise an exception
    # page.driver.debug
  end

  debugit "Does have debugging" do
    # ...
    # This is OK
    page.driver.debug
  end
end

And that's it. Happy debugging!

Say Thanks
Respond

1 Response
Add your response

22876
0  9zs63go3svdnd irbanenk0xrsd1hjb1qasiz5o3rxu1zk6yb8nakiobsskveieu9crtqeysy52z2pvo5gqazwthy5szuqeo5gmlqyxigk30sf9tqic58tmedxgyu ub6jnc6seaxr

Hi! Good tutorial.
Can you post an example of use with your code to debug network traffic?
I know "page.driver.network_traffic" but how can I use it with your code? (I starting with ruby)
Thanks.

over 1 year ago ·