Module: Appom::Helpers::DebugHelpers
- Defined in:
- lib/appom/helpers.rb
Overview
Debugging helpers
Instance Method Summary collapse
-
#debug_elements_info(*find_args) ⇒ Object
Get information about all elements matching a locator.
-
#dump_page_source(prefix = 'page_source') ⇒ Object
Dump current page source for debugging.
-
#screenshot_action(action_name) ⇒ Object
Take before/after screenshots around an action.
-
#screenshot_failure(test_name, exception = nil) ⇒ Object
Take screenshot on test failure with exception info.
-
#screenshot_sequence(name, interval: 1.0, max_duration: 10.0) ⇒ Object
Take screenshot sequence during complex interaction.
-
#take_debug_screenshot(prefix = 'debug') ⇒ Object
Take screenshot with automatic naming.
-
#take_element_screenshot(element_name, prefix = 'element') ⇒ Object
Take screenshot of specific element.
Instance Method Details
#debug_elements_info(*find_args) ⇒ Object
Get information about all elements matching a locator
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/appom/helpers.rb', line 236 def debug_elements_info(*find_args) elements = _all(*find_args) info = elements.map.with_index do |element, index| { index: index, tag_name: element.tag_name, text: element.text.to_s.strip, displayed: element.displayed?, enabled: element.enabled?, location: element.location, size: element.size, } rescue StandardError => e { index: index, error: e. } end log_info("Found #{elements.count} elements matching #{find_args.join(', ')}") info.each { |element_info| log_debug("Element info: #{element_info}") } info rescue StandardError => e log_error("Failed to get elements info: #{e.message}") [] end |
#dump_page_source(prefix = 'page_source') ⇒ Object
Dump current page source for debugging
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/appom/helpers.rb', line 219 def dump_page_source(prefix = 'page_source') return unless respond_to?(:driver) && driver = Time.now.strftime('%Y%m%d_%H%M%S') filename = "#{prefix}_#{timestamp}.xml" begin File.write(filename, driver.page_source) log_info("Page source saved: #{filename}") filename rescue StandardError => e log_error("Failed to save page source: #{e.message}") nil end end |
#screenshot_action(action_name) ⇒ Object
Take before/after screenshots around an action
204 205 206 |
# File 'lib/appom/helpers.rb', line 204 def screenshot_action(action_name, &) Screenshot.capture_before_after(action_name, &) end |
#screenshot_failure(test_name, exception = nil) ⇒ Object
Take screenshot on test failure with exception info
214 215 216 |
# File 'lib/appom/helpers.rb', line 214 def screenshot_failure(test_name, exception = nil) Screenshot.capture_on_failure(test_name, exception) end |
#screenshot_sequence(name, interval: 1.0, max_duration: 10.0) ⇒ Object
Take screenshot sequence during complex interaction
209 210 211 |
# File 'lib/appom/helpers.rb', line 209 def screenshot_sequence(name, interval: 1.0, max_duration: 10.0, &) Screenshot.capture_sequence(name, interval: interval, max_duration: max_duration, &) end |
#take_debug_screenshot(prefix = 'debug') ⇒ Object
Take screenshot with automatic naming
190 191 192 |
# File 'lib/appom/helpers.rb', line 190 def take_debug_screenshot(prefix = 'debug') Screenshot.capture(prefix) end |
#take_element_screenshot(element_name, prefix = 'element') ⇒ Object
Take screenshot of specific element
195 196 197 198 199 200 201 |
# File 'lib/appom/helpers.rb', line 195 def take_element_screenshot(element_name, prefix = 'element') element = send(element_name) Screenshot.capture("#{prefix}_#{element_name}", element: element) rescue StandardError => e log_error("Failed to take element screenshot: #{e.message}") nil end |