Class: Applitools::MatchWindowTask
- Inherits:
-
Object
- Object
- Applitools::MatchWindowTask
- Defined in:
- lib/eyes_selenium/eyes/match_window_task.rb
Defined Under Namespace
Classes: AppOutput
Instance Method Summary collapse
-
#initialize(eyes, agent_connector, session, driver, default_retry_timeout) ⇒ MatchWindowTask
constructor
noinspection RubyParameterNamingConvention.
- #match_window(region, retry_timeout, tag, run_once_after_wait = false) ⇒ Object
- #run(region, tag, wait_before_run = nil) ⇒ Object
- #run_with_intervals(region, tag, retry_timeout) ⇒ Object
Constructor Details
#initialize(eyes, agent_connector, session, driver, default_retry_timeout) ⇒ MatchWindowTask
noinspection RubyParameterNamingConvention
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eyes_selenium/eyes/match_window_task.rb', line 14 def initialize(eyes, agent_connector, session, driver, default_retry_timeout) @eyes = eyes @agent_connector = agent_connector @session = session @driver = driver @default_retry_timeout = default_retry_timeout @last_checked_window = nil # +ChunkyPNG::Canvas+ @last_screenshot_bounds = Applitools::Region::EMPTY # +Applitools::Region+ @current_screenshot = nil # +ChunkyPNG::Canvas+ end |
Instance Method Details
#match_window(region, retry_timeout, tag, run_once_after_wait = false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/eyes_selenium/eyes/match_window_task.rb', line 25 def match_window(region, retry_timeout, tag,run_once_after_wait=false) if retry_timeout < 0 retry_timeout = default_retry_timeout end EyesLogger.debug "Retry timeout set to: #{retry_timeout}" start = Time.now res = if retry_timeout.zero? run(region, tag) elsif run_once_after_wait run(region, tag, retry_timeout) else run_with_intervals(region, tag, retry_timeout) end elapsed_time = Time.now - start EyesLogger.debug "match_window(): Completed in #{format('%.2f', elapsed_time)} seconds" @last_checked_window = @current_screenshot @last_screenshot_bounds = region.empty? ? Applitools::Region.new(0, 0, last_checked_window.width, last_checked_window.height) : region #noinspection RubyUnnecessaryReturnStatement driver.eyes.clear_user_inputs and return res end |
#run(region, tag, wait_before_run = nil) ⇒ Object
46 47 48 49 50 |
# File 'lib/eyes_selenium/eyes/match_window_task.rb', line 46 def run(region, tag, wait_before_run=nil) EyesLogger.debug "Trying matching once..." sleep(wait_before_run) if wait_before_run match(region, tag) end |
#run_with_intervals(region, tag, retry_timeout) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/eyes_selenium/eyes/match_window_task.rb', line 52 def run_with_intervals(region, tag, retry_timeout) # We intentionally take the first screenshot before starting the timer, to allow the page # just a tad more time to stabilize. EyesLogger.debug 'Matching with interval...' data = prep_match_data(region, tag, true) start = Time.now as_expected = agent_connector.match_window(session, data) EyesLogger.debug "First call result: #{as_expected}" return true if as_expected match_retry = Time.now - start while match_retry < retry_timeout sleep(MATCH_INTERVAL) EyesLogger.debug 'Matching...' return true if match(region, tag, true) match_retry = Time.now - start EyesLogger.debug "Elapsed time: #{match_retry}" end ## lets try one more time if we still don't have a match EyesLogger.debug 'Last attempt to match...' as_expected = match(region, tag) EyesLogger.debug "Match result: #{as_expected}" as_expected end |