Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
Last active May 1, 2024 21:29
Show Gist options
  • Save jasoncodes/6025475 to your computer and use it in GitHub Desktop.
Save jasoncodes/6025475 to your computer and use it in GitHub Desktop.
Remote Chrome browser for Capybara
On the shared machine:
Download http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.33.0.jar&can=2&q=
$ brew install chromedriver
$ java -jar selenium-server-standalone-2.33.0.jar
On the local machine:
Set `CHROME_HOSTNAME` in your `.env`, `.rbenv_vars`, or per run.
if ENV['CHROME_HOSTNAME'].present?
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:desired_capabilities => :chrome,
:url => "http://#{ENV['CHROME_HOSTNAME']}:4444/wd/hub"
)
end
Capybara.server_port = Capybara::Server.new(Rails.application).send(:find_available_port)
Capybara.app_host = "http://#{`hostname -s`.strip}.local:#{Capybara.server_port}"
else
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
end
Capybara.default_wait_time = 5
Capybara.javascript_driver = :chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment