-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚧🥒 Reduce Capybara / Cucumber config #3911
Draft
josemigallas
wants to merge
1
commit into
master
Choose a base branch
from
simple_capybara_config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'selenium/webdriver' | ||
require 'capybara/minitest' | ||
include Capybara::Minitest::Assertions | ||
|
||
# in case firefox is needed! | ||
#Capybara.register_driver :selenium do |app| | ||
# Capybara::Selenium::Driver.new(app, :browser => :firefox) | ||
#end | ||
|
||
DEFAULT_JS_DRIVER = :headless_chrome | ||
# in case firefox is needed! | ||
# DEFAULT_JS_DRIVER = :headless_firefox | ||
|
||
Capybara.default_driver = :rack_test | ||
Capybara.javascript_driver = DEFAULT_JS_DRIVER | ||
Capybara.default_selector = :css | ||
# Capybara.default_max_wait_time = 10 | ||
Capybara.disable_animation = true | ||
|
||
# Capybara 3 changes the default server to Puma. It can be reverted to the previous default of WEBRick by specifying: | ||
Capybara.server = :webrick | ||
|
||
# see http://www.elabs.se/blog/60-introducing-capybara-2-1 | ||
Capybara.configure do |config| | ||
config.default_driver = :rack_test | ||
config.javascript_driver = DEFAULT_JS_DRIVER | ||
config.raise_server_errors = true | ||
config.match = :prefer_exact | ||
config.always_include_port = true | ||
config.default_max_wait_time = 10 | ||
end | ||
|
||
# Needed because cucumber-rails requires capybara/cucumber | ||
# https://github.com/cucumber/cucumber-rails/blob/7b47bf1dda3368247bf2d45bcb17a224e80ec6fd/lib/cucumber/rails/capybara.rb#L3 | ||
# https://github.com/teamcapybara/capybara/blob/2.18.0/lib/capybara/cucumber.rb#L17-L19 | ||
Before '@javascript' do | ||
Capybara.current_driver = DEFAULT_JS_DRIVER | ||
end | ||
Capybara.javascript_driver = :headless_chrome | ||
Capybara.match = :prefer_exact # TODO: this is Capybara v1 default, we should use :one or :smart | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not change it to |
||
Capybara.server = :webrick # default is :puma | ||
|
||
BASE_DRIVER_OPTIONS = { | ||
args: [ | ||
# This is added in Capybara's default drivers. See https://github.com/teamcapybara/capybara/blob/0480f90168a40780d1398c75031a255c1819dce8/lib/capybara/registrations/drivers.rb#L37-L38 | ||
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary | ||
'--disable-site-isolation-trials', | ||
# When width < 1200px, vertical navigation overlaps the page's main content and that will make | ||
# some cucumbers fail | ||
'--window-size=1200,2048', | ||
] | ||
}.freeze | ||
|
||
Before '@chrome' do | ||
Capybara.current_driver = :chrome | ||
end | ||
|
||
Before '@firefox' do | ||
Capybara.current_driver = :firefox | ||
end | ||
|
||
Around '@security' do |scenario, block| | ||
with_forgery_protection(&block) | ||
end | ||
|
||
# monkeypatch to fix | ||
# not opened for reading (IOError) | ||
# /cucumber-1.3.20/lib/cucumber/formatter/interceptor.rb:33:in `each' | ||
# /cucumber-1.3.20/lib/cucumber/formatter/interceptor.rb:33:in `collect' | ||
# /cucumber-1.3.20/lib/cucumber/formatter/interceptor.rb:33:in `method_missing' | ||
require 'cucumber/formatter/interceptor' | ||
class Cucumber::Formatter::Interceptor::Pipe | ||
def is_a?(klass) | ||
super || klass == IO | ||
end | ||
end | ||
|
||
Capybara.register_driver :firefox do |app| | ||
Capybara::Selenium::Driver.new(app, browser: :firefox) | ||
end | ||
|
||
Capybara.register_driver :headless_firefox do |app| | ||
options = Selenium::WebDriver::Firefox::Options.new | ||
|
||
options.add_argument('-headless') | ||
options.add_argument('--window-size=1280,2048') | ||
|
||
driver = Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) | ||
|
||
driver | ||
end | ||
|
||
Capybara.register_driver :firefox do |app| | ||
options = Selenium::WebDriver::Firefox::Options.new | ||
|
||
options.add_argument('--window-size=1280,2048') | ||
|
||
driver = Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) | ||
|
||
driver | ||
end | ||
|
||
# Use this driver to debug scenarios locally by adding tag @chrome on top of the scenario | ||
Capybara.register_driver :chrome do |app| | ||
options = Selenium::WebDriver::Chrome::Options.new | ||
options.add_argument('--window-size=1280,2048') | ||
options.add_argument('--disable-search-engine-choice-screen') | ||
options = Selenium::WebDriver::Options.chrome(**BASE_DRIVER_OPTIONS) | ||
|
||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) | ||
end | ||
|
||
Capybara.register_driver :headless_chrome do |app| | ||
options = Selenium::WebDriver::Options.chrome( | ||
logging_prefs: { performance: 'ALL', browser: 'ALL' }, | ||
perf_logging_prefs: { enableNetwork: true } | ||
) | ||
options = Selenium::WebDriver::Options.chrome(**BASE_DRIVER_OPTIONS) | ||
|
||
options.logging_prefs = { performance: 'ALL', browser: 'ALL' } | ||
|
||
options.add_option(:perf_logging_prefs, enableNetwork: true) | ||
|
||
options.add_argument('--headless=new') | ||
options.add_argument('--no-sandbox') | ||
options.add_argument('--disable-popup-blocking') | ||
options.add_argument('--window-size=1280,2048') | ||
options.add_argument('--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE *localhost*') | ||
options.add_argument('--disable-search-engine-choice-screen') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore? |
||
options.add_argument('--disable-gpu') | ||
|
||
options.add_preference(:browser, set_download_behavior: { behavior: 'allow' }) | ||
|
||
timeout = 120 # default 60 | ||
client = Selenium::WebDriver::Remote::Http::Default.new(open_timeout: timeout, read_timeout: timeout) | ||
|
||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, http_client: client) | ||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, timeout: 120) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember this
@javascript
tag was heavily patched by us. I had some updates to upstreamcapybara/cucumber
but IIRC it required Ruby 3. So I can check about this now we have Ruby 3.1 merged.