class Applitools::MatchWindowTask

Constants

AppOutput
MATCH_INTERVAL

Attributes

agent_connector[R]
driver[R]
max_window_load_time[R]
session[R]

Public Class Methods

new(agent_connector, session, driver, max_window_load_time) click to toggle source
# File lib/eyes_selenium_ruby/eyes/match_window_task.rb, line 11
def initialize(agent_connector, session, driver, max_window_load_time)
  @agent_connector = agent_connector
  @session = session
  @driver = driver
  @max_window_load_time = max_window_load_time
  @last_checked_window = nil # +ChunkyPNG::Canvas+
  @current_screenshot = nil # +ChunkyPNG::Canvas+
end

Public Instance Methods

match_window(tag,run_once_after_wait=false) click to toggle source
# File lib/eyes_selenium_ruby/eyes/match_window_task.rb, line 20
def match_window(tag,run_once_after_wait=false)
  res = if max_window_load_time.zero? 
    run(tag)
  elsif run_once_after_wait
    run(tag, max_window_load_time)
  else
    run_with_intervals(tag, max_window_load_time)
  end

  driver.clear_user_inputs and return res
end
run(tag, wait_before_run=nil) click to toggle source
# File lib/eyes_selenium_ruby/eyes/match_window_task.rb, line 32
def run(tag, wait_before_run=nil)
  sleep(wait_before_run) if wait_before_run
  match(tag)
end
run_with_intervals(tag, total_run_time) click to toggle source
# File lib/eyes_selenium_ruby/eyes/match_window_task.rb, line 37
def run_with_intervals(tag, total_run_time)
  iterations = (total_run_time / MATCH_INTERVAL - 1).to_i
  iterations.times do
    sleep(MATCH_INTERVAL)
    return true if match(tag, true)
  end

  ## lets try one more time if we still don't have a match
  match(tag)
end

Private Instance Methods

match(tag, ignore_mismatch=false) click to toggle source
# File lib/eyes_selenium_ruby/eyes/match_window_task.rb, line 62
def match(tag, ignore_mismatch=false)
  data = prep_match_data(tag, ignore_mismatch)
  as_expected = agent_connector.match_window(session, data)
  # If the server stored this image, it will be used as a base for our next screenshot compression
  if !ignore_mismatch
    @last_checked_window = @current_screenshot
  end
  return as_expected
end
prep_match_data(tag, ignore_mismatch) click to toggle source
# File lib/eyes_selenium_ruby/eyes/match_window_task.rb, line 50
def prep_match_data(tag, ignore_mismatch)
  title = driver.title
  current_screenshot_encoded = Base64.decode64(driver.screenshot_as(:base64))
  @current_screenshot = ChunkyPNG::Image.from_blob(current_screenshot_encoded)
  compressed_screenshot = Applitools::Utils::ImageDeltaCompressor.compress_by_raw_blocks(@current_screenshot,
                                                                              current_screenshot_encoded,
                                                                              @last_checked_window)
  app_output = AppOutput.new(title, nil)

  return Applitools::MatchWindowData.new(app_output, driver.user_inputs, tag, ignore_mismatch, compressed_screenshot)
end