Capybara Selenium Headless Chrome config for CI/CD

by Giang, last updated 15 Aug 2019

Default Capybara Selenium headless Chrome has high chance of not working properly on CI/CD. The following config works on Bitbucket Pipelines

Capybara.register_driver :custom_chrome_headless do |app|
  client =
  client.read_timeout = 120

  browser_options = do |opts|
    opts.args << '--headless'
    opts.args << '--disable-gpu'
    # Workaround
    opts.args << '--disable-site-isolation-trials'
    opts.args << '--no-sandbox'
    opts.args << '--disable-dev-shm-usage'
    # opts.args << '--disable-setuid-sandbox'
    opts.args << 'window-size=1200,1100'
  end, browser: :chrome, options: browser_options, http_client: client)

Capybara.default_driver = :custom_chrome_headless