def _take_screenshot( self, user_inputs, # type: UserInputs region, # type: Region tag, # type: Text should_run_once_on_timeout, # type: bool check_settings, # type: CheckSettings retry_timeout, # type: int source, # type: Optional[Text], ): # type: (...) -> EyesScreenshot time_start = datetime.now() if retry_timeout == 0 or should_run_once_on_timeout: if should_run_once_on_timeout: datetime_utils.sleep(retry_timeout) screenshot = self._try_take_screenshot(user_inputs, region, tag, check_settings, source) else: screenshot = self._retry_taking_screenshot(user_inputs, region, tag, check_settings, retry_timeout, source) time_end = datetime.now() summary_ms = datetime_utils.to_ms((time_end - time_start).seconds) logger.debug( "MatchWindowTask._take_screenshot completed in {} ms".format( summary_ms)) return screenshot
def _retry_taking_screenshot( self, user_inputs, # type: UserInputs region, # type: Region tag, # type: Text check_settings, # type: CheckSettings retry_timeout_sec, # type: int source, # type: Optional[Text] ): # type: (...) -> EyesScreenshot start = datetime.now() # Start the retry timer. retry = datetime_utils.to_ms((datetime.now() - start).seconds) # The match retry loop. screenshot = self._taking_screenshot_loop( user_inputs, region, tag, check_settings, retry_timeout_sec, retry, start, source, None, ) # If we're here because we haven't found a match yet, try once more if not self._match_result.as_expected: logger.info("Window mismatch. Retrying...") return self._try_take_screenshot(user_inputs, region, tag, check_settings, source) return screenshot
def _retry_taking_screenshot( self, user_inputs, # type: UserInputs region, # type: Region tag, # type: Text ignore_mismatch, # type: bool check_settings, # type: CheckSettings retry_timeout_sec, # type: int ): # type: (...) -> EyesScreenshot start = datetime.now() # Start the retry timer. retry = datetime_utils.to_ms((datetime.now() - start).seconds) # The match retry loop. screenshot = self._taking_screenshot_loop( user_inputs, region, tag, ignore_mismatch, check_settings, retry_timeout_sec, retry, start, ) # If we're here because we haven't found a match yet, try once more if not self._match_result.as_expected: return self._try_take_screenshot(user_inputs, region, tag, ignore_mismatch, check_settings) return screenshot