From 176ed3a6353985b4be956eb2bd9046e54f1eb403 Mon Sep 17 00:00:00 2001 From: Mike Korcynski Date: Fri, 1 Dec 2023 10:34:01 -0500 Subject: [PATCH] wip --- spec/rails_helper.rb | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 74d8c35..6b9c31a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -24,21 +24,47 @@ require 'spec_helper' require 'rspec/rails' +require 'capybara-screenshot/rspec' # Add additional requires below this line. Rails is not loaded until this point! require 'active_fedora/cleaner' - Capybara.server = :webrick +Capybara::Screenshot.autosave_on_failure = false + +if ENV['IN_DOCKER'].present? || ENV['HUB_URL'].present? + args = %w[disable-gpu no-sandbox whitelisted-ips window-size=1400,1400] + args.push('headless') if ActiveModel::Type::Boolean.new.cast(ENV['CHROME_HEADLESS_MODE']) + + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome("goog:chromeOptions" => { args: args }) + + Capybara.register_driver :selenium_chrome_headless_sandboxless do |app| + driver = Capybara::Selenium::Driver.new(app, + browser: :remote, + desired_capabilities: capabilities, + url: ENV['HUB_URL']) + # Fix for capybara vs remote files. Selenium handles this for us + driver.browser.file_detector = lambda do |argss| + str = argss.first.to_s + str if File.exist?(str) + end + + driver + end + Capybara.server_host = '0.0.0.0' + Capybara.server_port = 3010 + Capybara.javascript_driver = :selenium_chrome_headless_sandboxless + ip = IPSocket.getaddress(Socket.gethostname) + Capybara.app_host = "http://#{ip}:#{Capybara.server_port}" + Capybara.default_driver = :selenium_chrome_headless_sandboxless +else + # this is for github actions only -# this is for github actions only -if ENV['CI'] Webdrivers::Chromedriver.required_version = '106.0.5249.21' custom_chrome_path = '/opt/hostedtoolcache/chromium/1036826/x64/chrome' -end -# Adding chromedriver for js testing. + # Adding chromedriver for js testing. Capybara.register_driver :headless_chrome do |app| browser_options = ::Selenium::WebDriver::Chrome::Options.new browser_options.headless! @@ -59,6 +85,11 @@ Capybara.javascript_driver = :headless_chrome +end + +# Change to :chrome for js test debugging + + # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end