lib/appium_lib/common/patch.rb in appium_lib-0.3.16 vs lib/appium_lib/common/patch.rb in appium_lib-0.4.0
- old
+ new
@@ -2,32 +2,36 @@
module Appium::Common
# Implement useful features for element.
class Selenium::WebDriver::Element
# Note: For testing .text should be used over value, and name.
- # Fixes NoMethodError: undefined method `value' for #<Selenium::WebDriver::Element:0x..fa4a9148235390a44 id="1">
+ # Returns the value attribute
+ #
+ # Fixes NoMethodError: undefined method `value' for Selenium::WebDriver::Element
def value
self.attribute :value
end
- # Fixes NoMethodError: undefined method `name' for #<Selenium::WebDriver::Element
+ # Returns the name attribute
+ #
+ # Fixes NoMethodError: undefined method `name' for Selenium::WebDriver::Element
def name
self.attribute :name
end
- # Use tag_name to get element's type.
+ # Returns the type attribute
#
- # Tag name appears to be the same as type.
- #
# Fixes Selenium::WebDriver::Error::UnknownError: Not yet implemented
def tag_name
self.attribute :type
end
# For use with mobile tap.
#
+ # ```ruby
# execute_script 'mobile: tap', :x => 0.0, :y => 0.98
+ # ```
#
# https://github.com/appium/appium/wiki/Automating-mobile-gestures
# @return [OpenStruct] the relative x, y in a struct. ex: { x: 0.50, y: 0.20 }
def location_rel
xy = self.location
@@ -47,10 +51,11 @@
require 'selenium/webdriver/remote/response'
require 'selenium/webdriver/remote/commands'
require 'selenium/webdriver/remote/http/common'
require 'selenium/webdriver/remote/http/default'
+# @private
# Show http calls to the Selenium server.
#
# Invaluable for debugging.
def patch_webdriver_bridge
Selenium::WebDriver::Remote::Bridge.class_eval do
@@ -79,19 +84,53 @@
puts "#{verb} #{path_str}"
unless command_hash.nil? || command_hash.length == 0
print_command = command_hash.clone
print_command.delete :args if print_command[:args] == []
- ap print_command
+
+ mobile_find = 'mobile: find'
+ if print_command[:script] == mobile_find
+ args = print_command[:args]
+ puts "#{mobile_find}"#" #{args}"
+
+ # [[[[3, "sign"]]]] => [[[3, "sign"]]]
+ #
+ # [[[[4, "android.widget.EditText"], [7, "z"]], [[4, "android.widget.EditText"], [3, "z"]]]]
+ # => [[[4, "android.widget.EditText"], [7, "z"]], [[4, "android.widget.EditText"], [3, "z"]]]
+ args = args[0]
+ option = args[0].to_s.downcase
+ has_option = ! option.match(/all|scroll/).nil?
+ puts option if has_option
+
+ start = has_option ? 1 : 0
+
+ start.upto(args.length-1) do |selector_index|
+ selectors = args[selector_index]
+ selectors_size = selectors.length
+ selectors.each_index do |pair_index|
+ pair = selectors[pair_index]
+ res = $driver.dynamic_code_to_string pair[0], pair[1]
+
+ if selectors_size == 1 || pair_index >= selectors_size - 1
+ puts res
+ elsif selectors_size > 1 && pair_index < selectors_size
+ print res + '.'
+ end
+ end
+ end # start.upto
+ else
+ ap print_command
+ end
end
# puts "verb: #{verb}, path #{path}, command_hash #{command_hash.to_json}"
http.call verb, path, command_hash
end # def
end # class
end # def
# Print Appium's origValue error messages.
class Selenium::WebDriver::Remote::Response
+ # @private
def error_message
val = value
case val
when Hash
\ No newline at end of file