Update (2019): This article was written in 2015. Consider avoiding Poltergeist and PhantomJS mentioned in this article; they have since been deprecated.
Want to use the Web Inspector in Capybara/Selenium tests? The first thing you'll probably try is to use pry-byebug to pause your tests. You'll probably find that this doesn't work as intended.
scenario 'visiting the home page' do
visit root_path
binding.pry # ✗
end
Using binding.pry
will halt everything, making your browser not load anything because Rails can't respond to the request.
A better alternative is to use $stdin.gets
. This is what Poltergeist uses to pause execution. That method is not available in Capybara/Selenium though, so you'll need to add it in yourself:
$stderr.write 'Press enter to continue'
$stdin.gets
If you're using Capybara with Rspec, you can turn this into a helper. You can then just use pause
in your tests.
module PauseHelpers
def pause
$stderr.write 'Press enter to continue'
$stdin.gets
end
end
RSpec.configure do
config.include PauseHelpers, type: :feature
end
When using Poltergeist (for PhantomJS support), just use its Remote Debugging feature with the inspector: true
flag.