Skip to content

Instantly share code, notes, and snippets.

@sj26
Created February 27, 2019 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sj26/1579926c405a1652127a657669e155e7 to your computer and use it in GitHub Desktop.
Save sj26/1579926c405a1652127a657669e155e7 to your computer and use it in GitHub Desktop.
version: "3.6"
services:
app:
build: ..
depends_on:
- selenium
environment:
SELENIUM_HOST: selenium
selenium:
image: selenium/standalone-chrome
shm_size: 2g
Capybara.configure do |config|
config.default_driver = :selenium
# We use remote in docker compose to drive headless chrome in another container
selenium_host = ENV.fetch("SELENIUM_HOST", "127.0.0.1")
selenium_port = ENV.fetch("SELENIUM_PORT", "4444")
# Selenium container needs to talk back to us, but docker-compose run
# doesn't use a stable hostname, so listen on all addresses and ask for the
# current hostname and tell selenium to connect back on that. Also add the
# ephemeral port to all `visit` urls, etc.
config.server = :puma
config.server_host = "0.0.0.0"
config.app_host = "http://#{Socket.gethostname}"
config.always_include_port = true
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new app,
browser: :remote,
url: "http://#{selenium_host}:#{selenium_port}/wd/hub",
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment