Class: Applitools::Selenium::MatchWindowTask
- Inherits:
-
Object
- Object
- Applitools::Selenium::MatchWindowTask
- Defined in:
- lib/applitools/selenium/match_window_task.rb
Defined Under Namespace
Classes: AppOuptut
Constant Summary collapse
- MATCH_INTERVAL =
0.5
Instance Attribute Summary collapse
-
#default_retry_timeout ⇒ Object
readonly
Returns the value of attribute default_retry_timeout.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#eyes ⇒ Object
readonly
Returns the value of attribute eyes.
-
#last_checked_window ⇒ Object
readonly
Returns the value of attribute last_checked_window.
-
#last_screenshot_bounds ⇒ Object
readonly
Returns the value of attribute last_screenshot_bounds.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#initialize(eyes, session, driver, default_retry_timeout) ⇒ MatchWindowTask
constructor
A new instance of MatchWindowTask.
- #match_window(region, retry_timeout, tag, rotation, run_once_after_wait = false) ⇒ Object
- #run(region, tag, rotation, wait_before_run = nil) ⇒ Object
- #run_with_intervals(region, tag, rotation, retry_timeout) ⇒ Object
Constructor Details
#initialize(eyes, session, driver, default_retry_timeout) ⇒ MatchWindowTask
Returns a new instance of MatchWindowTask.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/applitools/selenium/match_window_task.rb', line 11 def initialize(eyes, session, driver, default_retry_timeout) @eyes = eyes @session = session @driver = driver @default_retry_timeout = default_retry_timeout @last_checked_window = nil # +ChunkyPNG::Canvas+ @last_screenshot_bounds = Applitools::Base::Region::EMPTY # +Applitools::Base::Region+ @current_screenshot = nil # +ChunkyPNG::Canvas+ end |
Instance Attribute Details
#default_retry_timeout ⇒ Object (readonly)
Returns the value of attribute default_retry_timeout.
8 9 10 |
# File 'lib/applitools/selenium/match_window_task.rb', line 8 def default_retry_timeout @default_retry_timeout end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
8 9 10 |
# File 'lib/applitools/selenium/match_window_task.rb', line 8 def driver @driver end |
#eyes ⇒ Object (readonly)
Returns the value of attribute eyes.
8 9 10 |
# File 'lib/applitools/selenium/match_window_task.rb', line 8 def eyes @eyes end |
#last_checked_window ⇒ Object (readonly)
Returns the value of attribute last_checked_window.
8 9 10 |
# File 'lib/applitools/selenium/match_window_task.rb', line 8 def last_checked_window @last_checked_window end |
#last_screenshot_bounds ⇒ Object (readonly)
Returns the value of attribute last_screenshot_bounds.
8 9 10 |
# File 'lib/applitools/selenium/match_window_task.rb', line 8 def last_screenshot_bounds @last_screenshot_bounds end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
8 9 10 |
# File 'lib/applitools/selenium/match_window_task.rb', line 8 def session @session end |
Instance Method Details
#match_window(region, retry_timeout, tag, rotation, run_once_after_wait = false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/applitools/selenium/match_window_task.rb', line 22 def match_window(region, retry_timeout, tag, rotation, run_once_after_wait = false) retry_timeout = default_retry_timeout if retry_timeout < 0 Applitools::EyesLogger.debug "Retry timeout set to: #{retry_timeout}" start = Time.now res = if retry_timeout.zero? run(region, tag, rotation) elsif run_once_after_wait run(region, tag, rotation, retry_timeout) else run_with_intervals(region, tag, rotation, retry_timeout) end elapsed_time = Time.now - start Applitools::EyesLogger.debug "match_window(): Completed in #{format('%.2f', elapsed_time)} seconds" @last_checked_window = @current_screenshot @last_screenshot_bounds = if region.empty? Applitools::Base::Region.new(0, 0, last_checked_window.width, last_checked_window.height) else region end driver.clear_user_inputs GC.start res end |
#run(region, tag, rotation, wait_before_run = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/applitools/selenium/match_window_task.rb', line 52 def run(region, tag, rotation, wait_before_run = nil) Applitools::EyesLogger.debug 'Trying matching once...' if wait_before_run Applitools::EyesLogger.debug 'Waiting before run...' sleep(wait_before_run) Applitools::EyesLogger.debug 'Waiting done!' end match(region, tag, rotation) end |
#run_with_intervals(region, tag, rotation, retry_timeout) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/applitools/selenium/match_window_task.rb', line 64 def run_with_intervals(region, tag, rotation, retry_timeout) # We intentionally take the first screenshot before starting the timer, to allow the page just a tad more time to # stabilize. Applitools::EyesLogger.debug 'Matching with intervals...' start = Time.now as_expected = match(region, tag, rotation, true) Applitools::EyesLogger.debug "First call result: #{as_expected}" return true if as_expected Applitools::EyesLogger.debug "Not as expected, performing retry (total timeout #{retry_timeout})" match_retry = Time.now - start while match_retry < retry_timeout Applitools::EyesLogger.debug 'Waiting before match...' sleep(MATCH_INTERVAL) Applitools::EyesLogger.debug 'Done! Matching...' return true if match(region, tag, rotation, true) match_retry = Time.now - start Applitools::EyesLogger.debug "Elapsed time: #{match_retry}" end # Let's try one more time if we still don't have a match. Applitools::EyesLogger.debug 'Last attempt to match...' as_expected = match(region, tag, rotation) Applitools::EyesLogger.debug "Match result: #{as_expected}" as_expected end |