diff --git a/lib/appium_lib/common/patch.rb b/lib/appium_lib/common/patch.rb index a27ae311..f143395e 100644 --- a/lib/appium_lib/common/patch.rb +++ b/lib/appium_lib/common/patch.rb @@ -90,7 +90,14 @@ def raw_execute(command, opts = {}, command_hash = nil) puts "#{verb} #{path_str}" unless command_hash.nil? || command_hash.length == 0 - print_command = command_hash.clone + print_command = {} + # For complex_find, we pass a whole array + if command_hash.kind_of? Array + print_command[:args] = [command_hash.clone] + print_command[:script] = 'mobile: find' if command == :complex_find + else + print_command = command_hash.clone + end print_command.delete :args if print_command[:args] == [] mobile_find = 'mobile: find' diff --git a/lib/appium_lib/device/device.rb b/lib/appium_lib/device/device.rb index 286922f5..4b01fab8 100644 --- a/lib/appium_lib/device/device.rb +++ b/lib/appium_lib/device/device.rb @@ -41,6 +41,18 @@ module Device # @!method shake # Cause the device to shake + #@!method complex_find + # Find an element by a complex array of criteria. Available criteria + # are listed in [link here]. Criteria are formed by creating an array + # of arrays, each containing a selector and that selector's value. + # + # ```ruby + # complex_find [[2, 'Sau'], [14, true]] # => Find a clickable element + # # whose names starts with 'Sau' + # ``` + # @param all (Symbol) If not falsy, will use the 'all' option in your find + # @param selectors (Array) The selectors to find elements with. + # @!method hide_keyboard # Hide the onscreen keyboard # @param close_key (String) the name of the key which closes the keyboard. @@ -97,6 +109,24 @@ def current_context=(context=null) add_endpoint_method(:hide_keyboard, 'session/:session_id/appium/device/hide_keyboard') do def hide_keyboard(close_key='Done') execute :hide_keyboard, {}, keyName: close_key + + add_endpoint_method(:complex_find, 'session/:session_id/appium/app/complex_find') do + def complex_find(all, selectors=nil) + if selectors.nil? + selectors = all.dup + all = false + end + + selector_array = all ? ['all'] : [] + selector_array.push selectors + + ids = execute :complex_find, {}, [selectors] + if all && ids.length > 1 + + return ids.map {|id| Selenium::WebDriver::Element.new self, element_id_from(id)} + else + return Selenium::WebDriver::Element.new self, element_id_from(ids) + end end end