Skip to content

Commit

Permalink
unify headless chrome and normal chrome tests
Browse files Browse the repository at this point in the history
allows you to specify a specific driver via environment variable

lets you switch between headless and non-headless chrome via env variable
  • Loading branch information
fiveNinePlusR committed Oct 12, 2024
1 parent 589c9a3 commit 5c63994
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .env.test.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set this to true if you want to see the chrome instance during testing
NO_HEADLESS_CHROME=false

# Use if you need a special chrome path during testing
# CHROME_SERVICE_PATH=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ logfile

/config/master.key
.vscode/extensions.json
/.env.test.local
27 changes: 18 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,29 @@
ex.run_with_retry retry: 3
end

Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
service = Selenium::WebDriver::Service.chrome
if ENV.fetch('CHROME_SERVICE_PATH', false) # rubocop:disable Style/IfUnlessModifier
service.executable_path = File.expand_path(ENV.fetch('CHROME_SERVICE_PATH'))
end

Capybara.register_driver :selenium_headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu window-size=2000,1000] }
Capybara.register_driver :selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
unless ENV.fetch('NO_HEADLESS_CHROME', false)
options.add_argument('--headless')
options.add_argument('--window-size=2000,1000')
end

options.add_argument('--disable-gpu')

Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options,
service: service
)

Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end

Capybara.javascript_driver = :selenium_chrome_headless
# Capybara.javascript_driver = :selenium_chrome
Capybara.javascript_driver = :selenium_chrome

# == Mock Framework
#
Expand Down

0 comments on commit 5c63994

Please sign in to comment.