Set download directory to work with headless chrome 77

This commit is contained in:
Thomas Walpole 2019-08-17 13:12:50 -07:00
parent ea6486b328
commit 32b2261baf
2 changed files with 5 additions and 0 deletions

1
.rspec
View File

@ -2,3 +2,4 @@
--order random
--require rspec/instafail
--format RSpec::Instafail
--format progress

View File

@ -13,9 +13,13 @@ Selenium::WebDriver::Chrome.path = '/usr/bin/google-chrome-beta' if ENV['CI'] &&
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.headless! if ENV['HEADLESS']
browser_options.add_option(:w3c, ENV['W3C'] != 'false')
# Chromedriver 77 requires setting this for headless mode on linux
# browser_options.add_preference('download.default_directory', Capybara.save_path)
browser_options.add_preference(:download, default_directory: Capybara.save_path)
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, timeout: 30).tap do |driver|
# Set download dir for Chrome < 77
driver.browser.download_path = Capybara.save_path
end
end