Connecting to selenium/standalone-chrome

selenium
capybara
2.0

#1

I’m having a problem connecting from my host container to selenium/standalone-chrome (and perhaps back).

Important details:

  • Capybara server is run on the host container at 0.0.0.0:4100
  • Test code determines the host’s advertised IP address e.g. 172.1.1.1
  • Capybara Instructions execute on selenium/standalone-chrome container via api call to http://127.0.0.1:4444/wd/hub and gives it urls such as http://dummy.com.172.1.1.1.xip.io:4100 to visit the server on the host container.
  • This works on an OSX host with manually running the selenium container with docker run -p 4444:4444 selenium/standalone-chrome:3.0.1-germanium

Interaction (host ip 172.1.1.1)

  1. host api call to selenium -> http://127.0.0.1:4444/wd/hub
  2. selenium browser visit -> 172.1.1.1:4100

config.yml

This abbreviated snippet shows the relevant parts:

version: 2
executorType: docker
containerInfo:
  - image: alienfast/ruby:1.0.3
    env:
      - RAILS_ENV=test
  - image: selenium/standalone-chrome:3.0.1-germanium
jobs:
  build:
    working_directory: /root/af
    steps:
      - checkout

      - run:
          name: Run tests
          command: |
            mkdir -p test-reports/cucumber
            bundle exec rake "knapsack_pro:cucumber[--format junit --out test-reports/cucumber/junit.xml]"

I had tried to manually run the image like I do locally but that didn’t work and seemed unnecessary, so I changed to run the same as I do mysql and bound to the host container, but experience the same error.

Questions

What am I missing?

  1. Should capybara test code be able to connect to selenium on 127.0.0.1:4444 with this configuration?
  2. Should the selenium container be able to connect to the host container at <host_ip>:4100?
  3. How can I debug this on the server - does add-ssh-keys allow me to login to 2.0?

#2

I seem to have broken through.

I think the key may have been that I added EXPOSE 4100 to the primary image. I am not currently successfully testing, but I have connected and am receiving a javascript error from selenium, so that is progress.


#3

@rosskevin I have the same issue, can not connect to ChromeDriver, have the errors like:

  Selenium::WebDriver::Error::WebDriverError:
             Unable to find chromedriver. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.

can you tell me how to expose the port 4100 within circleci config file?


#4

I’m not sure how to EXPOSE 4100 within circle ci config, I’m guessing you can only do this by customizing your container image. Circle ci support should be able to tell you.


#5

Here is my configuration:

# .circleci/config.yml
version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.1-node
        environment:
          RAILS_ENV: test
          SELENIUM_DRIVER_URL: http://localhost:4444/wd/hub
      - image: circleci/postgres:9.6.3-alpine
      - image: selenium/standalone-chrome:3.4.0
    # ...

And configuration for Capybara:

require 'capybara/rails'
require 'capybara/rspec'

Capybara.register_driver :selenium do |app|
  if ENV['SELENIUM_DRIVER_URL'].present?
    Capybara::Selenium::Driver.new(
      app,
      browser: :remote,
      url: ENV.fetch('SELENIUM_DRIVER_URL'),
      desired_capabilities: :chrome
    )
  else
    Capybara::Selenium::Driver.new(app, browser: :chrome)
  end
end

I hope this was helpful.

Marek


#6