3

I'm currently trying to setup headless chrome testing with Capybara in my docker-compose file.

However, I keep getting that chromedriver has failed to start because it had crashed.

Selenium::WebDriver::Error::UnknownError:
       unknown error: Chrome failed to start: crashed
         (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.9.36-moby x86_64)

Here is my DockerFile

    version: '3'
services:
  db:
    image: postgres
    networks:
      - zincplatform

  chromedriver:
    image: robcherry/docker-chromedriver:latest
    ports: 
      - "4444:4444"
    networks: 
      - zincplatform
    environment:
      CHROMEDRIVER_WHITELISTED_IPS: ""

  redis:
    image: redis:latest
    networks:
      - zincplatform

  quoting-engine:
    build: ../quoting-engine
    environment:
      - DATABASE_URL=postgresql://postgres:@db/zinc_quoting_engine_development
    command: bash -c "
        rm -f tmp/pids/server.pid \
        && bundle exec rails server -p 3001 -b '0.0.0.0'
      "
    volumes:
      - ../quoting-engine:/qe
    ports:
      - "3001:3001"
    networks:
      - zincplatform
    depends_on:
      - db
      - redis

  core:
    build: .
    environment:
      - DATABASE_URL=postgresql://postgres:@db/zinc_development
      - DOCKER=true
    command: bash -c "
        rm -f tmp/pids/server.pid \
        ; bundle exec rake db:migrate \
        ; foreman start -f Procfile.docker
      "
    volumes:
      - .:/zinc-core
    ports:
      - "3000:3000"
      - "8081:8081"
    networks:
      - zincplatform
    depends_on:
      - quoting-engine
      - db
      - redis
      - chromedriver

networks:
  zincplatform:
    driver: bridge

Here is my capybara.rb file which I use to select chrome driver

require "selenium/webdriver"

Capybara.ignore_hidden_elements = true

Capybara.javascript_driver = :headless_chrome

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

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu window-size=1440,900] },
  )

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    url: "http://chromedriver:4444/wd/hub",
    desired_capabilities: capabilities
end

RSpec.configure do |config|
  config.before(:each, js: true) do |example|
    Capybara.current_driver = select_driver(example)
    VCR.configure do |c|
      c.allow_http_connections_when_no_cassette = true
    end
  end
end

def select_driver(example)
  return unless example.metadata[:js]

  if example.metadata[:js] == :debug
    :chrome
  else
    :headless_chrome
  end
end

I followed exactly how I saw tutorials had set up chrome driver using port 4444 and that particular path.

  • Don't expose port 4444, if you are working with newer versions of docker-compose. – enderland Jul 28 '17 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.