0

I am using Selenium and trying to configure the Chrome driver to start in the background, that is I don't want the window to take focus. The idea is that running the test suite does not disrupt my flow when I am coding. I want the window focus to remain on the actual code editor, not on the newly created chrome window.

So I found this answer: Selenium - chrome Driver fail to start in background (without a start-up window)

But it uses Java. I need a Ruby solution.

I am currently using the Chrome driver as this:

Capybara.default_driver = :chrome

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

How can I achieve what I described?

Community
  • 1
  • 1
Nerian
  • 15,901
  • 13
  • 66
  • 96

1 Answers1

1

Translating from the original Java, you just need to add the startup argument to your Capabilities and pass that to the new Driver instance:

capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    "chromeOptions" => {"args" => [ "--no-startup-window" ]})

Capybara.default_driver = :chrome

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome,
     :desired_capabilities => capabilities)
end

Reference: https://sites.google.com/a/chromium.org/chromedriver/capabilities

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
  • 1
    Excellent, it does start the chrome browser in the background. Nonetheless, Capybara doesn't start to run the tests unless I click on the browser and give it focus. Is there a way to fake it? – Nerian Feb 11 '16 at 11:43
  • How about this alternate approach? I can update answer if this works for you: https://github.com/karma-runner/karma-chrome-launcher/issues/10#issuecomment-132606226 – Andrew Regan Feb 11 '16 at 12:33
  • I think I will just use a headless browser, and switch to selenium when I need to debug something. Thanks :) – Nerian Feb 11 '16 at 12:50
  • @Nerian Selenium (Chrome driver to be exact) [doesn't support](http://stackoverflow.com/a/43063728/2444725) Chrome browser in `--no-startup-window` mode. – Lightman Mar 28 '17 at 08:08