user2490003
user2490003

Reputation: 11920

Stopping Capybara + Selenium from opening a browser window during JS tests

I'm using RSpec with Capybara. On tests marked js: true it uses the default javascript driver (Selenium).

The test itself passes (see below), but I noticed it opens a Firefox window and then immediately closes it while running the test. As you can see below, the test is pretty straightforward and I don't have anything like save_and_open_page anywhere in there.

  1. Why do is it do this?
  2. Is there a way to disable this? If I have several dozen JS spec tests in the future I don't want a window opening up for each of them.

Thanks!

# rails_helper
require "spec_helper"
require "rspec/rails"
require "capybara/rails"
require "capybara/rspec"

# Test
it "user can sign in", js: true do
    visit root_path
    click_tab("sign_up")

    fill_in "session[email]", with: "[email protected]"
    fill_in "session[password]", with: "gr4ce!"
    click_submit

    expect(current_path).to eq(home_index_path)
end

Upvotes: 1

Views: 1136

Answers (1)

Thomas Cullen
Thomas Cullen

Reputation: 268

This happens because the Selenium driver uses firefox to execute the javascript in the test. You can use a headless browser such as phantom.js which wont open a browser window. The poltergiest gem is probably what you are looking for.

Upvotes: 3

Related Questions