mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Use load_selenium
class method for requiring selenium-webdriver
. (#2013)
* Use `load_selenium` class method for requiring `selenium-webdriver`. This change relates to this issue: https://github.com/teamcapybara/capybara/issues/2011 `Capybara::Selenium::Driver#load_selenium` is bumped to a class method which is called either during `Selenium::Driver` instantiation or before Selenium is used.
This commit is contained in:
parent
9b3c4fb411
commit
431482b751
2 changed files with 19 additions and 18 deletions
|
@ -494,6 +494,7 @@ Capybara.register_driver :selenium_chrome do |app|
|
|||
end
|
||||
|
||||
Capybara.register_driver :selenium_chrome_headless do |app|
|
||||
Capybara::Selenium::Driver.load_selenium
|
||||
browser_options = ::Selenium::WebDriver::Chrome::Options.new
|
||||
browser_options.args << '--headless'
|
||||
browser_options.args << '--disable-gpu' if Gem.win_platform?
|
||||
|
|
|
@ -13,6 +13,23 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
|
||||
attr_reader :app, :options
|
||||
|
||||
def self.load_selenium
|
||||
require 'selenium-webdriver'
|
||||
# Fix for selenium-webdriver 3.4.0 which misnamed these
|
||||
unless defined?(::Selenium::WebDriver::Error::ElementNotInteractableError)
|
||||
::Selenium::WebDriver::Error.const_set('ElementNotInteractableError', Class.new(::Selenium::WebDriver::Error::WebDriverError))
|
||||
end
|
||||
unless defined?(::Selenium::WebDriver::Error::ElementClickInterceptedError)
|
||||
::Selenium::WebDriver::Error.const_set('ElementClickInterceptedError', Class.new(::Selenium::WebDriver::Error::WebDriverError))
|
||||
end
|
||||
rescue LoadError => e
|
||||
if e.message =~ /selenium-webdriver/
|
||||
raise LoadError, "Capybara's selenium driver is unable to load `selenium-webdriver`, please install the gem and add `gem 'selenium-webdriver'` to your Gemfile if you are using bundler."
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
def browser
|
||||
unless @browser
|
||||
if firefox?
|
||||
|
@ -38,7 +55,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
end
|
||||
|
||||
def initialize(app, **options)
|
||||
load_selenium
|
||||
self.class.load_selenium
|
||||
@session = nil
|
||||
@app = app
|
||||
@browser = nil
|
||||
|
@ -472,21 +489,4 @@ private
|
|||
arg
|
||||
end
|
||||
end
|
||||
|
||||
def load_selenium
|
||||
require 'selenium-webdriver'
|
||||
# Fix for selenium-webdriver 3.4.0 which misnamed these
|
||||
unless defined?(::Selenium::WebDriver::Error::ElementNotInteractableError)
|
||||
::Selenium::WebDriver::Error.const_set('ElementNotInteractableError', Class.new(::Selenium::WebDriver::Error::WebDriverError))
|
||||
end
|
||||
unless defined?(::Selenium::WebDriver::Error::ElementClickInterceptedError)
|
||||
::Selenium::WebDriver::Error.const_set('ElementClickInterceptedError', Class.new(::Selenium::WebDriver::Error::WebDriverError))
|
||||
end
|
||||
rescue LoadError => e
|
||||
if e.message =~ /selenium-webdriver/
|
||||
raise LoadError, "Capybara's selenium driver is unable to load `selenium-webdriver`, please install the gem and add `gem 'selenium-webdriver'` to your Gemfile if you are using bundler."
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue