Class: HeadlessBrowserTool::Tools::VisualDiffTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/headless_browser_tool/tools/visual_diff_tool.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/headless_browser_tool/tools/visual_diff_tool.rb', line 11

def execute
  # Capture current state
  current_state = capture_page_state

  # Compare with previous state if exists
  previous_state = browser.previous_state || {}

  changes = {
    url_changed: previous_state[:url] != current_state[:url],
    title_changed: previous_state[:title] != current_state[:title],
    new_elements: find_new_elements(previous_state[:elements], current_state[:elements]),
    removed_elements: find_removed_elements(previous_state[:elements], current_state[:elements]),
    text_changes: find_text_changes(previous_state[:texts], current_state[:texts]),
    form_values_changed: compare_form_values(previous_state[:forms], current_state[:forms]),
    new_images: current_state[:images] - (previous_state[:images] || []),
    viewport_position: current_state[:scroll]
  }

  # Store current state for next comparison
  browser.previous_state = current_state

  # Return human-readable summary
  summarize_changes(changes, current_state)
end