Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3723)

Unified Diff: chrome/test/pyautolib/pyauto.py

Issue 10095018: Added a new PyAuto method WaitForDomNode() which allows tests to block until a specified node exist… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created a new exception class JavascriptRuntimeException in place of RuntimeException. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/pyautolib/dom_mutation_observer.js ('k') | chrome/test/pyautolib/pyauto_errors.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/pyautolib/pyauto.py
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index afcc7f134f9a9073e1ec8315b43329f68b84bd97..1f644402e22882edc151249081a270f48b77aa60 100755
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -2975,7 +2975,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
occurs on a DOM node specified by |selector|.
Args:
- mutation_type: One of 'add', 'remove', or 'change'.
+ mutation_type: One of 'add', 'remove', 'change', or 'exists'.
selector: A DOMSelector object defining the DOM node to watch. The node
must already exist if |mutation_type| is 'change'.
expected_value: Optional regular expression to match against the node's
@@ -2992,9 +2992,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
Raises:
pyauto_errors.JSONInterfaceError if the automation call returns an error.
- RuntimeError if the injected javascript MutationObserver returns an error.
+ pyauto_errors.JavascriptRuntimeError if the injected javascript
+ MutationObserver returns an error.
"""
- assert mutation_type in ('add', 'remove', 'change'), \
+ assert mutation_type in ('add', 'remove', 'change', 'exists'), \
'Unexpected value "%s" for mutation_type.' % mutation_type
assert isinstance(selector, domselector.DOMSelector), \
'Unexpected type: selector is not a instance of DOMSelector.'
@@ -3020,9 +3021,34 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
jsreturn = self.ExecuteJavascript(js, **kwargs)
if jsreturn != 'success':
self.RemoveEventObserver(observer_id)
- raise RuntimeError(jsreturn)
+ raise pyauto_errors.JavascriptRuntimeError(jsreturn)
return observer_id
+ def WaitForDomNode(self, selector, expected_value=None, timeout=-1, **kwargs):
+ """Waits until a node matching selector exists in the DOM.
+
+ NOTE: This does NOT poll. It returns as soon as the node appears, or
+ immediately if the node already exists.
+
+ Args:
+ selector: A DOMSelector object defining the DOM node to wait for.
+ expected_value: Optional regular expression to match against the node's
+ textContent attribute. Defaults to None.
+ timeout: Time to wait for the node to exist before raising an exception,
+ defaults to the default automation timeout.
+
+ Any additional keyword arguments are passed on to ExecuteJavascript and
+ can be used to select the tab where the DOM MutationObserver is created.
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ pyauto_errors.JavascriptRuntimeError if the injected javascript
+ MutationObserver returns an error.
+ """
+ observer_id = self.AddDomMutationObserver('exists', selector,
+ expected_value, **kwargs)
+ self.GetNextEvent(observer_id, timeout=timeout)
+
def GetNextEvent(self, observer_id=-1, blocking=True, timeout=-1):
"""Waits for an observed event to occur.
« no previous file with comments | « chrome/test/pyautolib/dom_mutation_observer.js ('k') | chrome/test/pyautolib/pyauto_errors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698