From e5ca1534e0b6937a91b28e32d0748eaa10396c2b Mon Sep 17 00:00:00 2001 From: molsky Date: Mon, 13 Apr 2015 12:52:26 +0300 Subject: [PATCH 1/3] Add 'Wait Until Page Not Contains Element' -keyword --- src/Selenium2Library/keywords/_waiting.py | 23 ++++++++++++++++++- test/acceptance/keywords/waiting.txt | 8 +++++-- .../html/javascript/delayed_events.html | 10 ++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Selenium2Library/keywords/_waiting.py b/src/Selenium2Library/keywords/_waiting.py index 565e11867..f0a167333 100644 --- a/src/Selenium2Library/keywords/_waiting.py +++ b/src/Selenium2Library/keywords/_waiting.py @@ -62,6 +62,27 @@ def wait_until_page_contains_element(self, locator, timeout=None, error=None): error = "Element '%s' did not appear in " % locator self._wait_until(timeout, error, self._is_element_present, locator) + def wait_until_page_not_contains_element(self, locator, timeout=None, error=None): + """Waits until element specified with `locator` disappears from current page. + + Fails if `timeout` expires before the element disappears. See + `introduction` for more information about `timeout` and its + default value. + + `error` can be used to override the default error message. + + See also `Wait Until Page Contains`, `Wait For Condition`, + `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until + Keyword Succeeds`. + """ + def check_present(): + present = self._is_element_present(locator) + if not present: + return + else: + return error or "Element '%s' did not disappear in %s" % (locator, self._format_timeout(timeout)) + self._wait_until_no_error(timeout, check_present) + def wait_until_element_is_visible(self, locator, timeout=None, error=None): """Waits until element specified with `locator` is visible. @@ -154,4 +175,4 @@ def _wait_until_no_error(self, timeout, wait_func, *args): def _format_timeout(self, timeout): timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs - return robot.utils.secs_to_timestr(timeout) + return robot.utils.secs_to_timestr(timeout) \ No newline at end of file diff --git a/test/acceptance/keywords/waiting.txt b/test/acceptance/keywords/waiting.txt index 909532d8f..aed39ccde 100644 --- a/test/acceptance/keywords/waiting.txt +++ b/test/acceptance/keywords/waiting.txt @@ -17,6 +17,11 @@ Wait Until Page Contains Element Wait Until Page Contains Element new div 2 seconds Run Keyword And Expect Error Element '%cnon-existent' did not appear in 100 milliseconds Wait Until Page Contains Element %cnon-existent 0.1 seconds +Wait Until Page Not Contains Element + [Documentation] Tests also that format characters (e.g. %c) are handled correctly in error messages + Wait Until Page Not Contains Element not_present 2 seconds + Run Keyword And Expect Error Element 'content' did not disappear in 100 milliseconds Wait Until Page Not Contains Element content 0.1 seconds + Wait Until Element Is Visible Run Keyword And Expect Error Element 'hidden' was not visible in 100 milliseconds Wait Until Element Is Visible hidden 0.1 Wait Until Element Is Visible hidden 2 s @@ -27,5 +32,4 @@ Wait Until Element Is Enabled Run Keyword And Expect Error Element 'id=disabled' was not enabled in 100 milliseconds Wait Until Element Is Enabled id=disabled 0.1 Wait Until Element Is Enabled id=disabled 2 s Run Keyword And Expect Error Element locator 'id=invalid' did not match any elements after 100 milliseconds Wait Until Element Is Enabled id=invalid 0.1 - Run Keyword And Expect Error User error message Wait Until Element Is Enabled id=invalid 0.1 User error message - + Run Keyword And Expect Error User error message Wait Until Element Is Enabled id=invalid 0.1 User error message \ No newline at end of file diff --git a/test/resources/html/javascript/delayed_events.html b/test/resources/html/javascript/delayed_events.html index 8b3bf4c04..9e40c48e0 100644 --- a/test/resources/html/javascript/delayed_events.html +++ b/test/resources/html/javascript/delayed_events.html @@ -4,6 +4,7 @@