DEV Community

ruanshiron
ruanshiron

Posted on

Resolves error when using image selenium/standalone-chromium with Capybara (Rails)

When trying to use the selenium/standalone-chrome image with rails I got a very annoying error and the cause is still unknown. But it was resolved by replacing it with another image.

Here is what happened.

Environment

# docker-compose.yml

version: '3.9'
services:
  web:
    # ...
  db:
    # ...
  webdriver_chrome:
    image: selenium/standalone-chromium:117.0
    ports:
      - 4444:4444
      - 5900:5900
Enter fullscreen mode Exit fullscreen mode
# spec/support/capybara.rb

Capybara.register_driver :remote_chrome do |app|
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument('--headless')
  options.add_argument('--no-sandbox')
  options.add_argument('--disable-dev-shm-usage')
  options.add_argument('--window-size=1400,1400')

  Capybara::Selenium::Driver.new(
    app,
    browser: :remote,
    url: ENV['SELENIUM_REMOTE_HOST'],
    options:
  )
end

RSpec.configure do |config|
  config.before(:each, type: :system) do
    driven_by :rack_test
  end

  config.before(:each, type: :system, js: true) do
    if ENV['SELENIUM_REMOTE_HOST'].present?
      Capybara.server_host = IPSocket.getaddress(Socket.gethostname)
      Capybara.app_host = "http://#{Capybara.server_host}"
      driven_by :remote_chrome
    else
      driven_by :selenium_chrome_headless
    end
  end
end
Enter fullscreen mode Exit fullscreen mode

Errors

      Selenium::WebDriver::Error::SessionNotCreatedError:
        Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
          (chrome not reachable)
          (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Enter fullscreen mode Exit fullscreen mode

How to temporarily fix it!

Replacing selenium/standalone-chromium:117.0 with seleniarm/standalone-chromium:117.0

-    image: selenium/standalone-chromium:117.0
+    image: seleniarm/standalone-chromium:117.0
Enter fullscreen mode Exit fullscreen mode

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now