diff --git a/src/Selenium2Library/__init__.py b/src/Selenium2Library/__init__.py index ef23abd70..a50702568 100644 --- a/src/Selenium2Library/__init__.py +++ b/src/Selenium2Library/__init__.py @@ -86,7 +86,7 @@ class Selenium2Library( ROBOT_LIBRARY_SCOPE = 'GLOBAL' ROBOT_LIBRARY_VERSION = VERSION - def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page Screenshot'): + def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page Screenshot', ajax_wait_framework=None): """Selenium2Library can be imported with optional arguments. `timeout` is the default timeout used to wait for all waiting actions. @@ -94,11 +94,7 @@ def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page 'implicit_wait' is the implicit timeout that Selenium waits when looking for elements. - It can be later set with `Set Selenium Implicit Wait`. - See `WebDriver: Advanced Usage`__ section of the SeleniumHQ documentation - for more information about WebDriver's implicit wait functionality. - - __ http://seleniumhq.org/docs/04_webdriver_advanced.html#explicit-and-implicit-waits + It can be later set with 'Set Selenium Implicit Wait'. `run_on_failure` specifies the name of a keyword (from any available libraries) to execute when a Selenium2Library keyword fails. By default @@ -107,15 +103,18 @@ def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page `Register Keyword To Run On Failure` keyword for more information about this functionality. + `ajax_wait_framework` waiting for an element by Java Script Framework, it support 'jquery' + Examples: - | Library `|` Selenium2Library `|` 15 | # Sets default timeout to 15 seconds | - | Library `|` Selenium2Library `|` 0 `|` 5 | # Sets default timeout to 0 seconds and default implicit_wait to 5 seconds | - | Library `|` Selenium2Library `|` 5 `|` run_on_failure=Log Source | # Sets default timeout to 5 seconds and runs `Log Source` on failure | - | Library `|` Selenium2Library `|` implicit_wait=5 `|` run_on_failure=Log Source | # Sets default implicit_wait to 5 seconds and runs `Log Source` on failure | - | Library `|` Selenium2Library `|` timeout=10 `|` run_on_failure=Nothing | # Sets default timeout to 10 seconds and does nothing on failure | + | Library `|` Selenium2Library `|` 15 | # Sets default timeout to 15 seconds | + | Library `|` Selenium2Library `|` 5 `|` Log Source | # Sets default timeout to 5 seconds and runs `Log Source` on failure | + | Library `|` Selenium2Library `|` timeout=10 `|` run_on_failure=Nothing | # Sets default timeout to 10 seconds and does nothing on failure | + | Library `|` Selenium2Library `|` timeout=10 `|` implicit_wait=5 `|` ajax_wait_framework=jquery | # Sets default timeout to 10 seconds, implicit_wait 5 seconds for jquery | """ for base in Selenium2Library.__bases__: base.__init__(self) self.set_selenium_timeout(timeout) self.set_selenium_implicit_wait(implicit_wait) self.register_keyword_to_run_on_failure(run_on_failure) + self.ajax_wait_framework = ajax_wait_framework + diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index d072049b9..b5363695c 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -534,6 +534,8 @@ def xpath_should_match_x_times(self, xpath, expected_xpath_count, message='', lo def _element_find(self, locator, first_only, required, tag=None): browser = self._current_browser() + if self.ajax_wait_framework: + self._ajax_active_check(self.ajax_wait_framework.lower()) elements = self._element_finder.find(browser, locator, tag) if required and len(elements) == 0: raise ValueError("Element locator '" + locator + "' did not match any elements.") @@ -657,3 +659,10 @@ def _page_should_not_contain_element(self, locator, tag, message, loglevel): self._info("Current page does not contain %s '%s'." % (element_name, locator)) + def _ajax_active_check(self, js_framework): + #TODO :dojo, Prototype, YUI, + js_condition_dict = {"jquery": "return window.jQuery.active == 0;",} + if js_framework in js_condition_dict: + self._info("waiting for %s finish ajax active" %js_framework ) + _timeout = int(self._implicit_wait_in_secs) if self._implicit_wait_in_secs else 10 + self.wait_for_condition(condition=js_condition_dict[js_framework], timeout=_timeout, error='ajax wait timeout')