From 4b87a835f0465048eee6f09b6f69713753446402 Mon Sep 17 00:00:00 2001 From: Jani Mikkonen Date: Wed, 3 Jul 2019 14:17:39 +0300 Subject: [PATCH] Add support for timeouts for attach applications Fixes #149 --- atests/configuration.robot | 11 +++++++- src/WhiteLibrary/keywords/configuration.py | 25 +++++++++++++++++++ src/WhiteLibrary/keywords/items/uiitem.py | 29 +++++++--------------- src/WhiteLibrary/utils/wait.py | 16 ++++++++++++ 4 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 src/WhiteLibrary/utils/wait.py diff --git a/atests/configuration.robot b/atests/configuration.robot index ed2a70a..52c8209 100644 --- a/atests/configuration.robot +++ b/atests/configuration.robot @@ -6,7 +6,7 @@ Library OperatingSystem Library String Library WhiteLibrary Suite Setup None -Suite Teardown White Configuration Parameters Restore +Test Teardown White Configuration Parameters Restore *** Test Cases *** Set White Busy Timeout @@ -29,6 +29,14 @@ Set White Drag Step Count ${WHITE_DRAG_STEP_COUNT} Get White Drag Step Count Should Be Equal ${WHITE_DRAG_STEP_COUNT} ${3} +Set White Attach Application Timeout + Set White Attach Application Timeout 10 s + ${ATTACH_APPLICATION_TIMEOUT} Get White Attach Application Timeout + Should Be Equal ${ATTACH_APPLICATION_TIMEOUT} 10000 milliseconds + +Get Default Attach Application Timeout + ${ATTACH_APPLICATION_TIMEOUT} Get White Attach Application Timeout + Should Be Equal ${ATTACH_APPLICATION_TIMEOUT} 30000 milliseconds *** Keywords *** White Configuration Parameters Restore @@ -36,4 +44,5 @@ White Configuration Parameters Restore Set White Busy Timeout 5000 ms Set White Find Window Timeout 30000 ms Set White Double Click Interval 0 ms + Set White Attach Application Timeout 30 s diff --git a/src/WhiteLibrary/keywords/configuration.py b/src/WhiteLibrary/keywords/configuration.py index ea03f37..c5dbde2 100644 --- a/src/WhiteLibrary/keywords/configuration.py +++ b/src/WhiteLibrary/keywords/configuration.py @@ -6,6 +6,7 @@ class WhiteConfigurationKeywords(LibraryComponent): + _attach_application_timeout = 30000 @keyword def set_white_busy_timeout(self, timeout): """Sets BusyTimeout for White and returns original value. @@ -82,6 +83,30 @@ def set_white_drag_step_count(value): logger.info("White DragStepCount set to" + str(CoreAppXmlConfiguration.Instance.DragStepCount)) return CoreAppXmlConfiguration.Instance.DragStepCount + @keyword + def set_white_attach_application_timeout(self, timeout): + """Sets timeout for attach application keywords for White and returns original value. + + ``timeout`` is the timeout value as Robot time string. + + Default timeout is 30 seconds. + + Note: This is not core TestStack.White feature + """ + original_timeout = self._attach_application_timeout + self._attach_application_timeout = self._get_timestr_in_milliseconds(timeout) + logger.info("White Attach Application Timeout set to " + str(self._attach_application_timeout)) + return original_timeout + + @keyword + def get_white_attach_application_timeout(self): + """Returns Attach Application Timeout value of White. + + See also `Set White Attach Application Timeout`. + Note: This is not core TestStack.White feature + """ + return self._get_milliseconds_as_timestr(self._attach_application_timeout) + @staticmethod @keyword def get_white_drag_step_count(): diff --git a/src/WhiteLibrary/keywords/items/uiitem.py b/src/WhiteLibrary/keywords/items/uiitem.py index 452bc6d..6b09281 100644 --- a/src/WhiteLibrary/keywords/items/uiitem.py +++ b/src/WhiteLibrary/keywords/items/uiitem.py @@ -3,7 +3,7 @@ from WhiteLibrary.keywords.librarycomponent import LibraryComponent from WhiteLibrary.keywords.robotlibcore import keyword from WhiteLibrary.utils.click import Clicks -import time +from WhiteLibrary.utils.wait import Wait class UiItemKeywords(LibraryComponent): @@ -98,10 +98,10 @@ def wait_until_item_exists(self, locator, timeout): See `Waiting and timeouts` for more information about waiting in WhiteLibrary. """ - self._wait_until_true(lambda: self._item_exists(locator), - timeout, - "Item with locator '{}' did not exist within {} seconds" - .format(locator, timestr_to_secs(timeout))) + Wait.until_true(lambda: self._item_exists(locator), + timeout, + "Item with locator '{}' did not exist within {} seconds" + .format(locator, timestr_to_secs(timeout))) @keyword def wait_until_item_does_not_exist(self, locator, timeout): @@ -116,22 +116,11 @@ def wait_until_item_does_not_exist(self, locator, timeout): See `Waiting and timeouts` for more information about waiting in WhiteLibrary. """ - self._wait_until_true(lambda: not self._item_exists(locator), - timeout, - "Item with locator '{}' still existed after {} seconds" - .format(locator, timestr_to_secs(timeout))) + Wait.until_true(lambda: not self._item_exists(locator), + timeout, + "Item with locator '{}' still existed after {} seconds" + .format(locator, timestr_to_secs(timeout))) def _item_exists(self, locator): search_criteria = self.state._get_search_criteria(locator) return self.state.window.Exists(search_criteria) - - @staticmethod - def _wait_until_true(condition, timeout, error_msg): - timeout = timestr_to_secs(timeout) - max_wait = time.time() + timeout - while True: - if condition(): - break - if time.time() > max_wait: - raise AssertionError(error_msg) - time.sleep(0.1) diff --git a/src/WhiteLibrary/utils/wait.py b/src/WhiteLibrary/utils/wait.py new file mode 100644 index 0000000..79a5575 --- /dev/null +++ b/src/WhiteLibrary/utils/wait.py @@ -0,0 +1,16 @@ +import time +from robot.utils import timestr_to_secs + + +class Wait: + @staticmethod + def until_true(condition, timeout, error_msg): + """Helper to wait until given condition is met.""" + timeout = timestr_to_secs(timeout) + max_wait = time.time() + timeout + while True: + if condition(): + break + if time.time() > max_wait: + raise AssertionError(error_msg) + time.sleep(0.1)