Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created February 8, 2018 23:40
Show Gist options
  • Select an option

  • Save missingfaktor/e2cfea4afa3dbd07824ebad1632c8aec to your computer and use it in GitHub Desktop.

Select an option

Save missingfaktor/e2cfea4afa3dbd07824ebad1632c8aec to your computer and use it in GitHub Desktop.
Running Capybara tests with Chrome, both locally and on Travis
require 'selenium-webdriver'
require 'capybara/rspec'
require 'capybara/dsl'
require 'capybara-screenshot/rspec'
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference :download, {
prompt_for_download: false,
default_directory: 'tmp/downloads'
}
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
driver.browser.save_screenshot(path)
end
Capybara.javascript_driver = :chrome
Capybara.default_max_wait_time = 5
Capybara.default_driver = :chrome
Capybara.save_path = 'tmp/screenshots'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
end
# We need this because Chrome fails to start in Travis' container infrastructure due to their tight resource
# constraints.
sudo: required
addons:
chrome: stable
language: ruby
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start" # We need xvfb - X Virtual FrameBuffer - to support applications requiring
# graphical interfaces, such as Chrome. We do not run Chrome in headless mode, but
# if we were, we would still need xvfb.
- sleep 10 # Give xvfb some time to start.
before_install:
- gem update --system
- gem --version
script:
- bundle exec rake test_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment