Arnab Datta
Arnab Datta

Reputation: 5206

Running cucumber and capybara in a docker container

I have a repo with e2e tests that uses

I want a docker container that:

This is what I have so far (using this docker image):

FROM 2glab/ruby-chrome-driver

RUN \
  apt-get update && \
  apt-get install -qy bundler && \
  apt-get install -qy cucumber

RUN useradd -d /home/<user> -ms /bin/bash -g root -G sudo -p <user> <password>
USER <user>
WORKDIR /home/<user>

RUN cd && git clone <my_repo_url>
WORKDIR <my_repo_folder>
RUN bundle install && bundle exec cucumber

Unfortunately, this results in a error:

unknown error: Chrome failed to start: crashed (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.9.87-linuxkit-aufs x86_64) (Selenium::WebDriver::Error::UnknownError

How would I fix this? Is chrome missing something? Is Chromedriver missing something? From what I can see, dependencies for chrome and chromedriver should be resolved in the docker image (see here).

Upvotes: 1

Views: 1100

Answers (2)

Bhudeb Kr Sarkar
Bhudeb Kr Sarkar

Reputation: 31

I had faced the same issue and fixed it by adding >options.add_argument('--disable-dev-shm-usage')>. Try addding the flag to options.

Upvotes: 0

Arnab Datta
Arnab Datta

Reputation: 5206

The solution was to configure a custom chrome driver instead of using the selenium_chrome_headless that ships with chromedriver+capybara:

require 'selenium-webdriver'

Capybara.register_driver :custom_chrome_headless do |app|
  browser_options = ::Selenium::WebDriver::Chrome::Options.new
  browser_options.args << '--headless'
  browser_options.args << '--no-sandbox'
  browser_options.args << '--disable-gpu'
  browser_options.args << '--window-size=1920,1080'
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: browser_options
  )
end

Capybara.configure do |config|
  config.default_driver = :custom_chrome_headless
  # Other irrelevant config stuff...
end

For some reason, this works but selenium_chrome_headless does not.

Upvotes: 1

Related Questions