lib/appium_lib/common/patch.rb in appium_lib-9.0.0 vs lib/appium_lib/common/patch.rb in appium_lib-9.1.0
- old
+ new
@@ -50,14 +50,17 @@
# Print JSON posted to Appium. Not scoped to an Appium module.
#
# Requires from lib/selenium/webdriver/remote.rb
require 'selenium/webdriver/remote/capabilities'
+require 'selenium/webdriver/remote/w3c_capabilities'
require 'selenium/webdriver/remote/bridge'
+require 'selenium/webdriver/remote/w3c_bridge'
require 'selenium/webdriver/remote/server_error'
require 'selenium/webdriver/remote/response'
require 'selenium/webdriver/remote/commands'
+require 'selenium/webdriver/remote/w3c_commands'
require 'selenium/webdriver/remote/http/common'
require 'selenium/webdriver/remote/http/default'
# @private
# Show http calls to the Selenium server.
@@ -65,18 +68,19 @@
# Invaluable for debugging.
def patch_webdriver_bridge
Selenium::WebDriver::Remote::Bridge.class_eval do
# Code from lib/selenium/webdriver/remote/bridge.rb
def raw_execute(command, opts = {}, command_hash = nil)
- verb, path = Selenium::WebDriver::Remote::Bridge::COMMANDS[command] ||
- fail(ArgumentError, "unknown command: #{command.inspect}")
- path = path.dup
+ verb, path = commands(command) || raise(ArgumentError, "unknown command: #{command.inspect}")
+ path = path.dup
path[':session_id'] = @session_id if path.include?(':session_id')
begin
- opts.each { |key, value| path[key.inspect] = escaper.escape(value.to_s) }
+ opts.each do |key, value|
+ path[key.inspect] = escaper.escape(value.to_s)
+ end
rescue IndexError
raise ArgumentError, "#{opts.inspect} invalid for #{command.inspect}"
end
# convert /// into /
@@ -105,14 +109,15 @@
# avoid backslash escape quotes in strings. "\"a\"" => "a"
Appium::Logger.info print_command.ai.gsub('\"', '"')
else
Appium::Logger.ap_info print_command
end
- else # non-standard command hash
+ elsif command_hash
+ # non-standard command hash
# It's important to output this for debugging problems.
# for example invalid JSON will not be a Hash
- Appium::Logger.ap_info command_hash if command_hash
+ Appium::Logger.ap_info command_hash
end
delay = $driver.global_webdriver_http_sleep
sleep delay if !delay.nil? && delay > 0
# Appium::Logger.info "verb: #{verb}, path #{path}, command_hash #{command_hash.to_json}"
http.call verb, path, command_hash
@@ -129,11 +134,11 @@
val = value
case val
when Hash
msg = val['origValue'] || val['message'] or return 'unknown error'
- msg << " (#{ val['class'] })" if val['class']
+ msg << " (#{val['class']})" if val['class']
when String
msg = val
else
msg = "unknown error, status=#{status}: #{val.inspect}"
end
@@ -142,7 +147,15 @@
end
end
class Selenium::WebDriver::Remote::Http::Common # rubocop:disable Style/ClassAndModuleChildren
remove_const :DEFAULT_HEADERS if defined? DEFAULT_HEADERS
- DEFAULT_HEADERS = { 'Accept' => CONTENT_TYPE, 'User-Agent' => "appium/ruby_lib/#{::Appium::VERSION}" }
+ DEFAULT_HEADERS = { 'Accept' => CONTENT_TYPE, 'User-Agent' => "appium/ruby_lib/#{::Appium::VERSION}" }.freeze
+end
+
+def patch_remote_driver_commands
+ Selenium::WebDriver::Remote::Bridge.class_eval do
+ def commands(command)
+ ::Appium::Driver::Commands::COMMAND[command]
+ end
+ end
end