mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Updates for selenium 4 latest alpha - Fix issue #2431
This commit is contained in:
parent
bd179928d2
commit
e0823f4fd1
6 changed files with 113 additions and 45 deletions
|
@ -7,13 +7,14 @@ gem 'pkg-config' # needed by nokogiri
|
|||
gem 'xpath', github: 'teamcapybara/xpath'
|
||||
gem 'rack', github: 'rack/rack'
|
||||
gem 'sinatra', github: 'sinatra/sinatra', branch: 'master'
|
||||
gem 'rspec', github: 'rspec/rspec'
|
||||
gem 'rspec-core', github: 'rspec/rspec-core'
|
||||
gem 'rspec-support', github: 'rspec/rspec-support'
|
||||
gem 'rspec-mocks', github: 'rspec/rspec-mocks'
|
||||
gem 'rspec-expectations', github: 'rspec/rspec-expectations'
|
||||
gem 'rspec', github: 'rspec/rspec', branch: 'main'
|
||||
gem 'rspec-core', github: 'rspec/rspec-core', branch: 'main'
|
||||
gem 'rspec-support', github: 'rspec/rspec-support', branch: 'main'
|
||||
gem 'rspec-mocks', github: 'rspec/rspec-mocks', branch: 'main'
|
||||
gem 'rspec-expectations', github: 'rspec/rspec-expectations', branch: 'main'
|
||||
gem 'cucumber', github: 'cucumber/cucumber-ruby'
|
||||
gem 'cucumber-core', github: 'cucumber/cucumber-ruby-core'
|
||||
gem 'cucumber-wire', github: 'cucumber/cucumber-ruby-wire'
|
||||
gem 'puma', github: 'puma/puma'
|
||||
gem 'selenium-webdriver', '>= 4.0.0.alpha7'
|
||||
|
||||
|
|
|
@ -9,32 +9,56 @@ Capybara.register_driver :selenium do |app|
|
|||
end
|
||||
|
||||
Capybara.register_driver :selenium_headless do |app|
|
||||
Capybara::Selenium::Driver.load_selenium
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
browser_options = ::Selenium::WebDriver::Firefox::Options.new
|
||||
|
||||
if browser_options.respond_to?(:headless!)
|
||||
browser_options.headless!
|
||||
else
|
||||
browser_options.args << '-headless'
|
||||
end
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox, options: browser_options)
|
||||
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox, capabilities: browser_options)
|
||||
else
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox, options: browser_options)
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_chrome do |app|
|
||||
Capybara::Selenium::Driver.load_selenium
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
|
||||
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
|
||||
opts.args << '--disable-site-isolation-trials'
|
||||
if opts.respond_to?(:add_argument)
|
||||
opts.add_argument('--disable-site-isolation-trials')
|
||||
else
|
||||
opts.args << '--disable-site-isolation-trials'
|
||||
end
|
||||
end
|
||||
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: browser_options)
|
||||
else
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
||||
end
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_chrome_headless do |app|
|
||||
Capybara::Selenium::Driver.load_selenium
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
|
||||
opts.args << '--headless'
|
||||
if opts.respond_to?(:headless!)
|
||||
opts.headless!
|
||||
else
|
||||
opts.args << '--headless'
|
||||
end
|
||||
opts.args << '--disable-gpu' if Gem.win_platform?
|
||||
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
|
||||
opts.args << '--disable-site-isolation-trials'
|
||||
end
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
||||
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: browser_options)
|
||||
else
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,9 +38,12 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
else
|
||||
Gem::Version.new(Selenium::WebDriver::VERSION)
|
||||
end
|
||||
|
||||
if selenium_webdriver_version < Gem::Version.new('3.5.0')
|
||||
warn "Warning: You're using an unsupported version of selenium-webdriver, please upgrade."
|
||||
end
|
||||
|
||||
selenium_webdriver_version
|
||||
rescue LoadError => e
|
||||
raise e unless e.message.include?('selenium-webdriver')
|
||||
|
||||
|
@ -66,7 +69,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
end
|
||||
end
|
||||
processed_options = options.reject { |key, _val| SPECIAL_OPTIONS.include?(key) }
|
||||
@browser = Selenium::WebDriver.for(options[:browser], **processed_options)
|
||||
@browser = Selenium::WebDriver.for(options[:browser], processed_options)
|
||||
|
||||
specialize_driver
|
||||
setup_exit_handler
|
||||
|
|
|
@ -8,7 +8,7 @@ module Capybara
|
|||
super
|
||||
end
|
||||
|
||||
def deprecate(*)
|
||||
def deprecate(*, **, &block)
|
||||
super unless @suppress_for_capybara
|
||||
end
|
||||
|
||||
|
|
|
@ -19,39 +19,71 @@ browser_options.add_preference('download.default_directory', Capybara.save_path)
|
|||
browser_options.add_preference(:download, default_directory: Capybara.save_path)
|
||||
|
||||
Capybara.register_driver :selenium_chrome do |app|
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, timeout: 30).tap do |driver|
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
driver_options = { browser: :chrome, timeout: 30 }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **driver_options).tap do |driver|
|
||||
# Set download dir for Chrome < 77
|
||||
driver.browser.download_path = Capybara.save_path
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_chrome_not_clear_storage do |app|
|
||||
chrome_options = {
|
||||
browser: :chrome,
|
||||
options: browser_options
|
||||
}
|
||||
Capybara::Selenium::Driver.new(app, **chrome_options.merge(clear_local_storage: false, clear_session_storage: false))
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
chrome_options = { browser: :chrome, clear_local_storage: false, clear_session_storage: false }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **chrome_options)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_chrome_not_clear_session_storage do |app|
|
||||
chrome_options = {
|
||||
browser: :chrome,
|
||||
options: browser_options
|
||||
}
|
||||
Capybara::Selenium::Driver.new(app, **chrome_options.merge(clear_session_storage: false))
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
chrome_options = { browser: :chrome, clear_session_storage: false }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **chrome_options)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_chrome_not_clear_local_storage do |app|
|
||||
chrome_options = {
|
||||
browser: :chrome,
|
||||
options: browser_options
|
||||
}
|
||||
Capybara::Selenium::Driver.new(app, **chrome_options.merge(clear_local_storage: false))
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
chrome_options = { browser: :chrome, clear_local_storage: false }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
end
|
||||
Capybara::Selenium::Driver.new(app, **chrome_options)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_driver_subclass_with_chrome do |app|
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
subclass = Class.new(Capybara::Selenium::Driver)
|
||||
subclass.new(app, browser: :chrome, options: browser_options, timeout: 30)
|
||||
chrome_options = { browser: :chrome, timeout: 30 }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
end
|
||||
|
||||
subclass.new(app, **chrome_options)
|
||||
end
|
||||
|
||||
module TestSessions
|
||||
|
|
|
@ -14,28 +14,36 @@ browser_options.profile = Selenium::WebDriver::Firefox::Profile.new.tap do |prof
|
|||
profile['browser.download.dir'] = Capybara.save_path
|
||||
profile['browser.download.folderList'] = 2
|
||||
profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv'
|
||||
profile['browser.startup.homepage'] = 'about:blank' # workaround bug in Selenium 4 alpha4-7
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_firefox do |app|
|
||||
# ::Selenium::WebDriver.logger.level = "debug"
|
||||
Capybara::Selenium::Driver.new(
|
||||
app,
|
||||
browser: :firefox,
|
||||
options: browser_options,
|
||||
timeout: 31
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
driver_options = { browser: :firefox, timeout: 31 }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
# Get a trace level log from geckodriver
|
||||
# :driver_opts => { args: ['-vv'] }
|
||||
)
|
||||
end
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **driver_options)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium_firefox_not_clear_storage do |app|
|
||||
Capybara::Selenium::Driver.new(
|
||||
app,
|
||||
browser: :firefox,
|
||||
clear_local_storage: false,
|
||||
clear_session_storage: false,
|
||||
options: browser_options
|
||||
)
|
||||
version = Capybara::Selenium::Driver.load_selenium
|
||||
driver_options = { browser: :firefox, clear_local_storage: false, clear_session_storage: false }.tap do |opts|
|
||||
if version >= Gem::Version.new('4.0.0.alpha6')
|
||||
opts[:capabilities] = browser_options
|
||||
else
|
||||
opts[:options] = browser_options
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **driver_options)
|
||||
end
|
||||
|
||||
module TestSessions
|
||||
|
|
Loading…
Reference in a new issue