DEV Community

n350071๐Ÿ‡ฏ๐Ÿ‡ต
n350071๐Ÿ‡ฏ๐Ÿ‡ต

Posted on

stop/pause headless Selenium testing with Capybara

๐Ÿ”— Parent Note

๐Ÿค” Situation

When you want to debug with real display.

The setting is like this.

#spec/rails_helper.rb
Capybara.register_driver :headless_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: browser_options,
    http_client: Selenium::WebDriver::Remote::Http::Default.new
  )
end
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
  opts.args << '--headless'
end

๐Ÿ‘ Solution

Comment out opts.args << '--headless' line.

#spec/rails_helper.rb
Capybara.register_driver :headless_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: browser_options,
    http_client: Selenium::WebDriver::Remote::Http::Default.new
  )
end
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
#  opts.args << '--headless'
end

๐Ÿ“š Reference

Discussion (1)

Collapse
hyosunko profile image
Mike • Edited on

I think a better solution would be adding configuration to specify js_driver in rails_helper

Capybara.javascript_driver = ENV.fetch('CAPYBARA_DRIVER', :headless_chrome).to_sym
Enter fullscreen mode Exit fullscreen mode

then you just specify env to display chrome browser in the terminal

CAPYBARA_DRIVER=chrome rspec spec/*_spec.rb
Enter fullscreen mode Exit fullscreen mode