Debug your capybara features with Chrome web inspector. Easily!
[Poltergeist][1] has the ability to [debug][2] 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!
[1]: https://github.com/jonleighton/poltergeist
[2]: https://github.com/jonleighton/poltergeist#remote-debugging-experimental
Written by Alejandro Fernández
Related protips
1 Response
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.