From 8b9d6ab60f61b0aaaad472c3c336e37bb2ab7a70 Mon Sep 17 00:00:00 2001 From: Lars Olesen Date: Thu, 16 Apr 2020 07:18:10 +0000 Subject: [PATCH] More --- spec/spec_helper.rb | 38 ++++-------------------------------- spec/support/chrome_setup.rb | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 spec/support/chrome_setup.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 619bc7c94fe4..5b2fa0a6ab3b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# https://medium.com/espark-engineering-blog/testing-your-jekyll-site-the-ruby-way-ccfa386a8318 + # Require all of the necessary gems require 'rspec' require 'capybara/rspec' @@ -5,7 +7,6 @@ require 'rack/test' require 'pry' require 'webdrivers' - RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true @@ -15,39 +16,8 @@ end # Configure Capybara to use Selenium. Capybara.register_driver :selenium do |app| - chrome_prefs = { - 'download' => { - 'default_directory' => './support/', - 'prompt_for_download' => false - }, - 'profile' => { - 'default_content_settings' => { 'multiple-automatic-downloads': 1 }, # for chrome version olde ~42 - 'default_content_setting_values' => { 'automatic_downloads': 1 }, # for chrome newe 46 - 'password_manager_enabled' => false - }, - 'safebrowsing' => { - 'enabled' => false, - 'disable_download_protection' => true - } - } - - # Set headless with docker friendly args. - chrome_args = %w[window-size=1024,768 disable-gpu no-sandbox disable-translate no-default-browser-check disable-popup-blocking] - # To run full browser instead of headless mode, run this command: HEADLESS=false rspec spec - unless ENV.fetch('HEADLESS', 'true') == 'false' - chrome_args += %w[headless] - end - - # Initialize chromedriver. - capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( - chromeOptions: { - prefs: chrome_prefs, - args: chrome_args - } - ) - driver = Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities) - - driver + # Configure selenium to use Chrome. + Capybara::Selenium::Driver.new(app, :browser => :chrome) end # Configure Capybara to load the website through rack-jekyll. # (force_build: true) builds the site before the tests are run, diff --git a/spec/support/chrome_setup.rb b/spec/support/chrome_setup.rb new file mode 100644 index 000000000000..1f237ee49c50 --- /dev/null +++ b/spec/support/chrome_setup.rb @@ -0,0 +1,37 @@ +# http://www.jeremyaldrich.net/en/latest/rspec_automated_browser_testing.html +Capybara.register_driver :selenium_chrome do |app| + # Set chrome download dir and auto confirm all "are you sure you want to download" to test downloading docs and pdfs. + chrome_prefs = { + 'download' => { + 'default_directory' => DownloadHelpers::PATH.to_s, + 'prompt_for_download' => false + }, + 'profile' => { + 'default_content_settings' => { 'multiple-automatic-downloads': 1 }, # for chrome version olde ~42 + 'default_content_setting_values' => { 'automatic_downloads': 1 }, # for chrome newe 46 + 'password_manager_enabled' => false + }, + 'safebrowsing' => { + 'enabled' => false, + 'disable_download_protection' => true + } + } + + # Set headless with docker friendly args. + chrome_args = %w[window-size=1024,768 disable-gpu no-sandbox disable-translate no-default-browser-check disable-popup-blocking] + # To run full browser instead of headless mode, run this command: HEADLESS=false rspec spec + unless ENV.fetch('HEADLESS', 'true') == 'false' + chrome_args += %w[headless] + end + + # Initialize chromedriver. + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( + chromeOptions: { + prefs: chrome_prefs, + args: chrome_args + } + ) + driver = Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities) + + driver +end \ No newline at end of file