Module: Appom::Helpers::WaitHelpers
- Includes:
- Retry::RetryMethods
- Defined in:
- lib/appom/helpers.rb
Overview
Common wait patterns
Instance Method Summary collapse
-
#wait_for_any(*element_names, timeout: nil) ⇒ Object
Wait for any of multiple elements to appear.
-
#wait_for_clickable(element_name, timeout: nil) ⇒ Object
Wait for element to be clickable (visible and enabled).
-
#wait_for_condition(element_name, description: 'custom condition', timeout: nil, &condition_block) ⇒ Object
Advanced: Wait for custom condition on element.
-
#wait_for_count(elements_name, count, timeout: nil) ⇒ Object
Wait for elements collection to have specific count.
-
#wait_for_disappear(element_name, timeout: nil) ⇒ Object
Wait for element to disappear.
-
#wait_for_invisible(element_name, timeout: nil) ⇒ Object
Wait for element to become invisible.
-
#wait_for_text_in_element(element_name, expected_text, timeout: nil) ⇒ Object
Wait for text to appear in element.
-
#wait_for_text_match(element_name, text, exact: false, timeout: nil) ⇒ Object
Wait for element text to match pattern.
Methods included from Retry::RetryMethods
#find_with_retry, #get_text_with_retry, #interact_with_retry, #wait_for_state_with_retry
Instance Method Details
#wait_for_any(*element_names, timeout: nil) ⇒ Object
Wait for any of multiple elements to appear
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/appom/helpers.rb', line 143 def wait_for_any(*element_names, timeout: nil) timeout ||= Appom.max_wait_time wait = Appom::Wait.new(timeout: timeout) wait.until do element_names.each do |element_name| return element_name if respond_to?("has_#{element_name}") && send("has_#{element_name}") end false end rescue Appom::WaitError raise Appom::ElementNotFoundError.new("any of: #{element_names.join(', ')}", timeout) end |
#wait_for_clickable(element_name, timeout: nil) ⇒ Object
Wait for element to be clickable (visible and enabled)
108 109 110 111 112 |
# File 'lib/appom/helpers.rb', line 108 def wait_for_clickable(element_name, timeout: nil) timeout ||= Appom.max_wait_time find_args = send("#{element_name}_params") Appom::SmartWait.until_clickable(*find_args, timeout: timeout) end |
#wait_for_condition(element_name, description: 'custom condition', timeout: nil, &condition_block) ⇒ Object
Advanced: Wait for custom condition on element
136 137 138 139 140 |
# File 'lib/appom/helpers.rb', line 136 def wait_for_condition(element_name, description: 'custom condition', timeout: nil, &condition_block) timeout ||= Appom.max_wait_time find_args = send("#{element_name}_params") Appom::SmartWait.until_condition(*find_args, timeout: timeout, description: description, &condition_block) end |
#wait_for_count(elements_name, count, timeout: nil) ⇒ Object
Wait for elements collection to have specific count
129 130 131 132 133 |
# File 'lib/appom/helpers.rb', line 129 def wait_for_count(elements_name, count, timeout: nil) timeout ||= Appom.max_wait_time find_args = send("#{elements_name}_params") Appom::SmartWait.until_count_equals(*find_args, count: count, timeout: timeout) end |
#wait_for_disappear(element_name, timeout: nil) ⇒ Object
Wait for element to disappear
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/appom/helpers.rb', line 158 def wait_for_disappear(element_name, timeout: nil) if respond_to?("has_no_#{element_name}") send("has_no_#{element_name}") else timeout ||= Appom.max_wait_time wait = Appom::Wait.new(timeout: timeout) wait.until do send(element_name) false rescue Appom::ElementNotFoundError true end end end |
#wait_for_invisible(element_name, timeout: nil) ⇒ Object
Wait for element to become invisible
122 123 124 125 126 |
# File 'lib/appom/helpers.rb', line 122 def wait_for_invisible(element_name, timeout: nil) timeout ||= Appom.max_wait_time find_args = send("#{element_name}_params") Appom::SmartWait.until_invisible(*find_args, timeout: timeout) end |
#wait_for_text_in_element(element_name, expected_text, timeout: nil) ⇒ Object
Wait for text to appear in element
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/appom/helpers.rb', line 174 def wait_for_text_in_element(element_name, expected_text, timeout: nil) timeout ||= Appom.max_wait_time wait = Appom::Wait.new(timeout: timeout) wait.until do element_text = get_text_with_retry(element_name, retries: 1) element_text&.include?(expected_text) rescue StandardError false end end |
#wait_for_text_match(element_name, text, exact: false, timeout: nil) ⇒ Object
Wait for element text to match pattern
115 116 117 118 119 |
# File 'lib/appom/helpers.rb', line 115 def wait_for_text_match(element_name, text, exact: false, timeout: nil) timeout ||= Appom.max_wait_time find_args = send("#{element_name}_params") Appom::SmartWait.until_text_matches(*find_args, text: text, exact: exact, timeout: timeout) end |