Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolesen committed Aug 13, 2021
1 parent ac63663 commit 8b9d6ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
38 changes: 4 additions & 34 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# 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'
require 'rack/jekyll'
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
Expand All @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions spec/support/chrome_setup.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8b9d6ab

Please sign in to comment.