Index: chrome/test/pyautolib/pyauto.py |
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py |
index afcc7f134f9a9073e1ec8315b43329f68b84bd97..ada2c9583f031b2c73606d09cecbc6bcd1a0486e 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 |
@@ -2994,7 +2994,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
pyauto_errors.JSONInterfaceError if the automation call returns an error. |
RuntimeError 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.' |
@@ -3023,6 +3023,30 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
raise RuntimeError(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. |
+ RuntimeError if the injected javascript MutationObserver returns an error. |
frankf
2012/04/16 23:53:07
nit: RuntimeError is mostly a 'relic', think about
craigdh
2012/04/16 23:58:40
Done.
|
+ """ |
+ 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. |