Search code examples
rspeccapybara

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

  • 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