DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

1 3

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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
hyosunko profile image
Mike • Edited

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay