'Is there a way to make Capybara do tests live in a browser?

I'd like to debug some of my tests and see what's actually happening. An easy way to do that would be to watch them play out in front of me. Is it possible to force Capybara to use an actual browser instance to run the tests visibly in front of you?



Solution 1:[1]

Of course it is possible! You can use selenium driver.

Add selenium-webdriver to your Gemfile. Then, in your spec_helper.rb you'll have to set

Capybara.javascript_driver = :selenium

When you'll launch your tests, a new Firefox window will open!

If you want Chrome to be opened, set the driver to :selenium_chrome

Remember to set :js => true in your test:

describe 'some test', :js => true do
 it "something" do
  .
  .
  .
 end
end

You can also learn more about drivers here

Solution 2:[2]

Mine (on an existing code-base) was a similar (but slightly different) fix, remove _headless from

driven_by :selenium_headless, using: :firefox

in config.before(:each, type: :system, js: true) do in the file spec/rails_helper.rb.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 dumbledad