Class: Appom::SmartWait::WaitConditions

Inherits:
Object
  • Object
show all
Defined in:
lib/appom/smart_wait.rb

Overview

Enhanced wait conditions beyond basic timeout/interval

Class Method Summary collapse

Class Method Details

.all_conditions(conditions) ⇒ Object

Combine conditions with AND logic



80
81
82
# File 'lib/appom/smart_wait.rb', line 80

def all_conditions(conditions)
  -> { conditions.all?(&:call) }
end

.any_condition(conditions) ⇒ Object

Combine conditions with OR logic



75
76
77
# File 'lib/appom/smart_wait.rb', line 75

def any_condition(conditions)
  -> { conditions.any?(&:call) }
end

.attribute_contains(element, attribute_name, expected_value) ⇒ Object

Wait for attribute to contain value



61
62
63
64
65
66
67
# File 'lib/appom/smart_wait.rb', line 61

def attribute_contains(element, attribute_name, expected_value)
  lambda do
    (element.attribute(attribute_name) || '').include?(expected_value.to_s)
  rescue StandardError
    false
  end
end

.attribute_equals(element, attribute_name, expected_value) ⇒ Object

Wait for element attribute to have specific value



95
96
97
98
99
100
101
102
# File 'lib/appom/smart_wait.rb', line 95

def attribute_equals(element, attribute_name, expected_value)
  lambda do
    actual_value = element.attribute(attribute_name)
    actual_value == expected_value
  rescue StandardError
    false
  end
end

.clickable(element) ⇒ Object

Condition for clickable element (used by factory methods)



105
106
107
108
109
110
111
112
113
114
# File 'lib/appom/smart_wait.rb', line 105

def clickable(element)
  lambda do
    return element.displayed? && element.enabled? if element

    # For factory method usage without element instance
    false
  rescue StandardError
    false
  end
end

.count_equals(expected_count) ⇒ Object

Condition for element count (used by factory methods)



140
141
142
143
144
145
146
# File 'lib/appom/smart_wait.rb', line 140

def count_equals(expected_count)
  lambda do |elements|
    elements.length == expected_count
  rescue StandardError
    false
  end
end

.custom_condition(&block) ⇒ Object

Create custom condition from block



70
71
72
# File 'lib/appom/smart_wait.rb', line 70

def custom_condition(&block)
  block
end

.element_clickable(element) ⇒ Object

Wait for element to be clickable (visible and enabled)



30
31
32
33
34
35
36
# File 'lib/appom/smart_wait.rb', line 30

def element_clickable(element)
  lambda do
    element.displayed? && element.enabled?
  rescue StandardError
    false
  end
end

.element_enabled(element) ⇒ Object

Wait for element to be enabled



21
22
23
24
25
26
27
# File 'lib/appom/smart_wait.rb', line 21

def element_enabled(element)
  lambda do
    element.enabled?
  rescue StandardError
    false
  end
end

.element_invisible(element) ⇒ Object

Wait for element to be invisible



85
86
87
88
89
90
91
92
# File 'lib/appom/smart_wait.rb', line 85

def element_invisible(element)
  lambda do
    !element.displayed?
  rescue StandardError
    # Element not found means it's invisible
    true
  end
end

.element_visible(element) ⇒ Object

Wait for element to be visible/displayed



12
13
14
15
16
17
18
# File 'lib/appom/smart_wait.rb', line 12

def element_visible(element)
  lambda do
    element.displayed?
  rescue StandardError
    false
  end
end

.invisibleObject

Condition for invisible element (used by factory methods)



131
132
133
134
135
136
137
# File 'lib/appom/smart_wait.rb', line 131

def invisible
  lambda do |element|
    !element.displayed?
  rescue StandardError
    true
  end
end

.text_changed(element, initial_text) ⇒ Object

Wait for text to change from initial value



52
53
54
55
56
57
58
# File 'lib/appom/smart_wait.rb', line 52

def text_changed(element, initial_text)
  lambda do
    element.text != initial_text
  rescue StandardError
    false
  end
end

.text_matches(expected_text, exact: false) ⇒ Object

Condition for text matching (used by factory methods)



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/appom/smart_wait.rb', line 117

def text_matches(expected_text, exact: false)
  lambda do |element|
    actual_text = element.text
    if exact
      actual_text == expected_text.to_s
    else
      actual_text.include?(expected_text.to_s)
    end
  rescue StandardError
    false
  end
end

.text_present(element, expected_text) ⇒ Object

Wait for text to be present



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/appom/smart_wait.rb', line 39

def text_present(element, expected_text)
  lambda do
    if expected_text.is_a?(Regexp)
      !(element.text =~ expected_text).nil?
    else
      element.text.include?(expected_text.to_s)
    end
  rescue StandardError
    false
  end
end