Skip to content

Instantly share code, notes, and snippets.

@motine
Created July 15, 2020 07:14
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 motine/8af309be7db58b76eb9b571b703acfa6 to your computer and use it in GitHub Desktop.
Save motine/8af309be7db58b76eb9b571b703acfa6 to your computer and use it in GitHub Desktop.
spec/support/config_capybara.rb
require 'capybara'
require 'capybara/rspec'
# please see notes in README.md
Capybara.server_host = '0.0.0.0'
Capybara.server_port = '56556'
Capybara.app_host = 'http://localhost:56556'
Capybara.register_driver(:host_chrome) do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => {'w3c' => false}, 'browserName' => 'chrome') # we need to set w3c to false so uploads do work; see https://github.com/SeleniumHQ/selenium/issues/7666 and https://stackoverflow.com/questions/58296774/ruby-selenium-webdriver-3-142-6-unable-to-upload-file-due-to-seleniumwebdriv
driver = Capybara::Selenium::Driver.new(app, browser: :remote, url: 'http://host.docker.internal:9515', desired_capabilities: caps)
driver.browser.file_detector = lambda do |args|
path = args.first.to_s
File.exist?(path) ? path : nil
end
driver
end
Capybara.default_driver = :host_chrome
Capybara.javascript_driver = :host_chrome
Capybara.server = :puma, { Silent: true } # do not use unicorn, because it makes trouble with the activerecord connection and it is massively slower
RSpec.configure do |config|
config.after(:suite) do
Capybara.reset_sessions!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment