Use chrome headless with circleci/ruby pre-built Docker image

chrome
docker
capybara
headless

#1

Hello,

After navigating and reading the multiple threads about the same issue and reading conflicting information, I am seeking guidance as to what is the way to go to run Rspec tests using Capybara and headless chrome with the pre-built Docker image from CircleCI. I was not able to make a successful connection (specs fail with Errno::ECONNREFUSED: Failed to open TCP connection to 127.0.0.1:4444 (Connection refused - connect(2) for "127.0.0.1" port 4444)

Current setup:

  • ruby 2.3.6
  • rails 4.2.7
  • rspec 3.7.0
  • capybara 2.13
  • selenium-webdriver 3.8
  • CircleCI pre-build image: circleci/ruby-2.3.6-node-browsers

spec/support/capybara.rb:

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :remote,
    url: 'http://localhost:4444/wd/hub',
    desired_capabilities: :chrome
  )
end

I am not sure what is wrong, could anyone point me out in the right direction?

Thanks!


#2

Try swapping localhost out for 127.0.0.1


#3

Thank you for your reply Ryan. I had already tried that but it didn’t work.

I got it working using the following:

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w(headless disable-gpu) }
  )

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: capabilities
  )
end

Is that how the selenium webdriver is supposed to be set up?

FWIW not having access to the pre-built Docker images’s Dockerfiles makes it harder to understand the setup.

Thank you,


#4

Not sure on the Ruby specific aspects of it.



#5

Thank you Ryan.

It would be more helpful if the actual Dockerfiles were accessible from Docker Hub (https://hub.docker.com/r/circleci/ruby/).

I’ll have a look at the Dockerfile.


#6

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.