Module: CandroidHelpers

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

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#multiple_traits(opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/candroid_helpers.rb', line 27

def multiple_traits opts = {}
  '''Pass an array of query elements. Determines the
  correct trait for page objects that can have multiple 
  acceptable traits.'''
  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



17
18
19
20
21
22
23
24
25
# File 'lib/candroid_helpers.rb', line 17

def once_element_exists opts = {}
  '''Performs a lambda action once the element exists.
  The default behavior is to touch the specified element.'''
  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

#until_element_exists(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/candroid_helpers.rb', line 6

def until_element_exists opts = {}
  '''Performs a lambda action until the element appears.
  The default action is to do nothing.'''
  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