Home > database >  Browser is launching for headless chrome capybara with Selenium webdriver
Browser is launching for headless chrome capybara with Selenium webdriver

Time:09-23

I'm trying to launch chrome in headless but the browser keeps on launching. Tried several different ways

  1. used chrome options and added arguments
  2. used chrome capabilities as well

My chrome version: 86 OS - ubuntu capybara - 3.32.2

First Helper file:

spec_helper.rb

Capybara.register_driver :headless_chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome,
                                 options: Selenium::WebDriver::Chrome::Options.new(args: %w[headless no-sandbox disable-gpu]))
end

Capybara.default_driver = :headless_chrome
Capybara.javascript_driver = :headless_chrome


Second try of Helper file:


Capybara.register_driver :headless_chrome do |app|
  Capybara::Selenium::Driver.new(
    app, 
    browser: :chrome,
    desired_capabilities:Selenium::WebDriver::Remote::Capabilities.chrome(
       chromeOptions: {
                       args: %w[headless disable-gpu disable-popup-blocking no-sandbox]
                      }
           )
  )
end

Capybara.default_driver = :headless_chrome
Capybara.javascript_driver = :headless_chrome

Thanks in advance

CodePudding user response:

Simplest way is to not register your own driver and just use the one provided by Capybara

Capybara.default_driver = :selenium_chrome_headless
Capybara.javascript_driver = :selenium_chrome_headless

Note - this will only work if you're not using rails system tests (no indication in your question that you're using rails though) since they override these settings - see the rails/rspec system test docs (driven_by) for that.

CodePudding user response:

Resolved this by adding chromeOptions separately and had to remove -- from all arguments

  • Related