Module: CandroidHelpers
- Defined in:
- lib/candroid_helpers.rb,
lib/candroid_helpers/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Method Summary collapse
-
#enter_text(opts = {}) ⇒ Object
Takes in a hash where the keys correspond to the ids of the text fields and the values correspond to the strings you want to enter.
-
#enter_text_by_index(arr = []) ⇒ Object
Takes in an array of strings.
-
#multiple_traits(opts = {}) ⇒ Object
Pass an array of query elements.
-
#once_element_exists(opts = {}) ⇒ Object
Performs a lambda action once the element exists.
-
#touch_if(opts = {}) ⇒ Object
Takes in a hash with the element key specified.
-
#until_element_exists(opts = {}) ⇒ Object
Performs a lambda action until the element appears.
Instance Method Details
#enter_text(opts = {}) ⇒ Object
Takes in a hash where the keys correspond to the ids of the text fields and the values correspond to the strings you want to enter.
70 71 72 73 74 75 76 77 |
# File 'lib/candroid_helpers.rb', line 70 def enter_text opts = {} opts.each do |key, value| key = key.to_s unless query("EditText id:'#{key}'").empty? query "EditText id:'#{key}'", setText: value end end end |
#enter_text_by_index(arr = []) ⇒ Object
Takes in an array of strings. Enters in the strings in order of the EditText indices.
58 59 60 61 62 63 64 |
# File 'lib/candroid_helpers.rb', line 58 def enter_text_by_index arr = [] arr.each_with_index do |string, index| unless query("EditText index:#{index}").empty? query "EditText index:#{index}", setText: string end end end |
#multiple_traits(opts = {}) ⇒ Object
Pass an array of query elements. Determines the correct trait for page objects that can have multiple acceptable traits.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/candroid_helpers.rb', line 30 def multiple_traits opts = {} timeout = opts[:timeout] || 10 traits = opts[:traits] || ["*"] trait = '' action = lambda do traits.each do |element| if element_exists element trait = element break end end !trait.empty? end wait_poll until: action, timeout: timeout do ; end trait # Return the one trait end |
#once_element_exists(opts = {}) ⇒ Object
Performs a lambda action once the element exists. The default behavior is to touch the specified element.
19 20 21 22 23 24 25 |
# File 'lib/candroid_helpers.rb', line 19 def once_element_exists opts = {} raise "No element given." if opts[:element].nil? timeout = opts[:timeout] || 10 action = opts[:action] || lambda { touch opts[:element] } wait_for_elements_exist [opts[:element]], timeout: timeout action.call end |
#touch_if(opts = {}) ⇒ Object
Takes in a hash with the element key specified. Touches the given element if it exists in the current view.
50 51 52 53 |
# File 'lib/candroid_helpers.rb', line 50 def touch_if opts = {} raise "No element given." if opts[:element].nil? touch opts[:element] if element_exists opts[:element] end |
#until_element_exists(opts = {}) ⇒ Object
Performs a lambda action until the element appears. The default action is to do nothing.
8 9 10 11 12 13 14 15 |
# File 'lib/candroid_helpers.rb', line 8 def until_element_exists opts = {} raise "No element given." if opts[:element].nil? timeout = opts[:timeout] || 10 action = opts[:action] || lambda { ; } wait_poll until_exists: opts[:element], timeout: timeout do action.call end end |