mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add default file detector when attaching files using selenium with a remote driver
This commit is contained in:
parent
bbda59c34b
commit
cc34066f4f
13 changed files with 34 additions and 57 deletions
|
@ -430,6 +430,10 @@ private
|
|||
::Capybara::Selenium::Node.new(self, native_node, initial_cache)
|
||||
end
|
||||
|
||||
def bridge
|
||||
browser.send(:bridge)
|
||||
end
|
||||
|
||||
def specialize_driver
|
||||
browser_type = browser.browser
|
||||
Capybara::Selenium::Driver.specializations.select { |k, _v| k === browser_type }.each_value do |specialization| # rubocop:disable Style/CaseEquality
|
||||
|
|
|
@ -108,10 +108,6 @@ private
|
|||
::Capybara::Selenium::ChromeNode.new(self, native_node, initial_cache)
|
||||
end
|
||||
|
||||
def bridge
|
||||
browser.send(:bridge)
|
||||
end
|
||||
|
||||
def chromedriver_version
|
||||
@chromedriver_version ||= begin
|
||||
caps = browser.capabilities
|
||||
|
|
|
@ -108,10 +108,6 @@ private
|
|||
::Capybara::Selenium::EdgeNode.new(self, native_node, initial_cache)
|
||||
end
|
||||
|
||||
def bridge
|
||||
browser.send(:bridge)
|
||||
end
|
||||
|
||||
def edgedriver_version
|
||||
@edgedriver_version ||= begin
|
||||
caps = browser.capabilities
|
||||
|
|
|
@ -13,12 +13,6 @@ module Capybara::Selenium::Driver::FirefoxDriver
|
|||
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)) ||
|
||||
driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bridge
|
||||
browser.send(:bridge)
|
||||
end
|
||||
end
|
||||
|
||||
module Capybara::Selenium::Driver::W3CFirefoxDriver
|
||||
|
|
|
@ -18,10 +18,6 @@ private
|
|||
def build_node(native_node, initial_cache = {})
|
||||
::Capybara::Selenium::SafariNode.new(self, native_node, initial_cache)
|
||||
end
|
||||
|
||||
def bridge
|
||||
browser.send(:bridge)
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::Selenium::Driver.register_specialization(/^(safari|Safari_Technology_Preview)$/,
|
||||
|
|
|
@ -299,11 +299,31 @@ private
|
|||
end
|
||||
|
||||
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
||||
path_names = value.to_s.empty? ? [] : value
|
||||
file_names = Array(path_names).map do |pn|
|
||||
Pathname.new(pn).absolute? ? pn : File.expand_path(pn)
|
||||
end.join("\n")
|
||||
native.send_keys(file_names)
|
||||
with_file_detector do
|
||||
path_names = value.to_s.empty? ? [] : value
|
||||
file_names = Array(path_names).map do |pn|
|
||||
Pathname.new(pn).absolute? ? pn : File.expand_path(pn)
|
||||
end.join("\n")
|
||||
native.send_keys(file_names)
|
||||
end
|
||||
end
|
||||
|
||||
def with_file_detector
|
||||
if driver.options[:browser] == :remote &&
|
||||
bridge.respond_to?(:file_detector) &&
|
||||
bridge.file_detector.nil?
|
||||
begin
|
||||
bridge.file_detector = lambda do |(fn, *)|
|
||||
str = fn.to_s
|
||||
str if File.exist?(str)
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
bridge.file_detector = nil
|
||||
end
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def set_content_editable(value) # rubocop:disable Naming/AccessorMethodName
|
||||
|
@ -359,6 +379,10 @@ private
|
|||
driver.browser
|
||||
end
|
||||
|
||||
def bridge
|
||||
browser.send(:bridge)
|
||||
end
|
||||
|
||||
def browser_action
|
||||
browser.action
|
||||
end
|
||||
|
|
|
@ -84,10 +84,6 @@ private
|
|||
end
|
||||
end
|
||||
|
||||
def bridge
|
||||
driver.browser.send(:bridge)
|
||||
end
|
||||
|
||||
def w3c?
|
||||
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)) ||
|
||||
capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
||||
|
|
|
@ -69,10 +69,6 @@ private
|
|||
end
|
||||
end
|
||||
|
||||
def bridge
|
||||
driver.browser.send(:bridge)
|
||||
end
|
||||
|
||||
def browser_version
|
||||
@browser_version ||= begin
|
||||
caps = driver.browser.capabilities
|
||||
|
|
|
@ -115,10 +115,6 @@ private
|
|||
actions
|
||||
end
|
||||
|
||||
def bridge
|
||||
driver.browser.send(:bridge)
|
||||
end
|
||||
|
||||
def upload(local_file)
|
||||
return nil unless local_file
|
||||
raise ArgumentError, "You may only upload files: #{local_file.inspect}" unless File.file?(local_file)
|
||||
|
|
|
@ -90,10 +90,6 @@ class Capybara::Selenium::SafariNode < Capybara::Selenium::Node
|
|||
|
||||
private
|
||||
|
||||
def bridge
|
||||
driver.browser.send(:bridge)
|
||||
end
|
||||
|
||||
def _send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new)
|
||||
case keys
|
||||
when *MODIFIER_KEYS
|
||||
|
|
|
@ -54,12 +54,6 @@ module TestSessions
|
|||
Chrome = Capybara::Session.new(CHROME_REMOTE_DRIVER, TestApp)
|
||||
end
|
||||
|
||||
TestSessions::Chrome.driver.browser.file_detector = lambda do |args|
|
||||
# args => ["/path/to/file"]
|
||||
str = args.first.to_s
|
||||
str if File.exist?(str)
|
||||
end
|
||||
|
||||
skipped_tests = %i[response_headers status_code trigger download]
|
||||
|
||||
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests do |example|
|
||||
|
|
|
@ -50,12 +50,6 @@ module TestSessions
|
|||
RemoteFirefox = Capybara::Session.new(FIREFOX_REMOTE_DRIVER, TestApp)
|
||||
end
|
||||
|
||||
TestSessions::RemoteFirefox.driver.browser.file_detector = lambda do |args|
|
||||
# args => ["/path/to/file"]
|
||||
str = args.first.to_s
|
||||
str if File.exist?(str)
|
||||
end
|
||||
|
||||
skipped_tests = %i[response_headers status_code trigger download]
|
||||
|
||||
Capybara::SpecHelper.run_specs TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests do |example|
|
||||
|
|
|
@ -39,12 +39,7 @@ Capybara.register_driver :selenium_ie do |app|
|
|||
Capybara::Selenium::Driver.new(app,
|
||||
browser: :remote,
|
||||
options: options,
|
||||
url: url).tap do |driver|
|
||||
driver.browser.file_detector = lambda do |args|
|
||||
str = args.first.to_s
|
||||
str if File.exist?(str)
|
||||
end
|
||||
end
|
||||
url: url)
|
||||
else
|
||||
Capybara::Selenium::Driver.new(
|
||||
app,
|
||||
|
|
Loading…
Reference in a new issue