Module: CiosHelpers

Defined in:
lib/cios_helpers.rb,
lib/cios_helpers/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#enter_text(opts = {}) ⇒ Object

Takes in a hash where the keys correspond to the ids or label of the text fields and the values correspond to the strings you want to enter.



72
73
74
75
76
77
78
79
80
# File 'lib/cios_helpers.rb', line 72

def enter_text opts = {}
  opts.each do |key, value|
    unless query("TextField marked:'#{key}'").empty?
      touch "TextField marked:'#{key}'"
      wait_for_elements_exist ["Keyboard"]
      keyboard_enter_text value
    end
  end
end

#enter_text_by_index(arr = []) ⇒ Object

Takes in an array of strings. Enters in the strings in order of the TextField indices.



58
59
60
61
62
63
64
65
66
# File 'lib/cios_helpers.rb', line 58

def enter_text_by_index arr = []
  arr.each_with_index do |string, index|
    unless query("TextField index:#{index}").empty?
      touch "TextField index:#{index}"
      wait_for_elements_exist ["Keyboard"]
      keyboard_enter_text 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/cios_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/cios_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/cios_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/cios_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