Dougui
Dougui

Reputation: 7232

Not able to run selenium with firefox, Capybara and Docker in headless mode

I'm trying to run tests with Selenium and Firefox with Capybara. When I run a test, it does a POST request to "http://127.0.0.1:4444:/sessions", it starts a server with geckodriver and I have a timeout error. I tried to do it manually by doing this command :

curl -d '{"desiredCapabilities": {"browserName": "firefox", "version": "", "platform": "ANY", "javascriptEnabled": 1, "cssSelectorsEnabled": 1, "takesScreenshot": 1, "nativeEvents": 0, "rotatable": 0, "unexpectedAlertBehaviour": "ignore", "moz:firefoxOptions": {"args": ["-headless"]}}, "capabilities": {"firstMatch": [{"browserName": "firefox", "moz:firefoxOptions": {}}]}}' http://127.0.0.1:4444/session

It fails and I have this message : Error: GDK_BACKEND does not match available displays. When I lauch xvfb-run geckodriver, it works but I have to find a way to launch geckodriver in headless mode with RSpec.

I'm on a docker env, so I don't have a xserver installed.

What can I do?

Edit

I have :

Firefox 52.4
Geckodriver 0.19.0
Capybara 2.13
Selenium-webdriver 3.6

Here is my configuration of selenium :

Capybara.register_driver :selenium do |app|
  require 'selenium/webdriver'
  Capybara::Selenium::Driver.new(app, :browser => :firefox)
end

Everything is running on docker.

Upvotes: 3

Views: 3219

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49870

Now that you have Firefox 56 (which is supported by geckodriver 0.19 and also supports headless mode, which Firefox 52 did not) you need to configure your driver to enable headless mode. Something along the lines of

Capybara.register_driver :selenium do |app|
  browser_options = ::Selenium::WebDriver::Firefox::Options.new()
  browser_options.args << '--headless'

  Capybara::Selenium::Driver.new(
    app,
    browser: :firefox,
    options: browser_options
  )
end

should do.

Upvotes: 12

Related Questions