Skip to content

Commit

Permalink
Merge pull request #139 from DylanLacey/complex_find
Browse files Browse the repository at this point in the history
Add complex find
  • Loading branch information
bootstraponline committed Apr 15, 2014
2 parents 38a9429 + bc20a71 commit 62dc430
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/appium_lib/common/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
30 changes: 30 additions & 0 deletions lib/appium_lib/device/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>) 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.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 62dc430

Please sign in to comment.