Chromium Code Reviews| Index: tools/telemetry/telemetry/page/actions/action_runner.py |
| diff --git a/tools/telemetry/telemetry/page/actions/action_runner.py b/tools/telemetry/telemetry/page/actions/action_runner.py |
| index cba75b293c5abc7f8143b682f977828fc652f3d8..cf5ddae409c80f90caa1cc7c1a282c0e4a3e5387 100644 |
| --- a/tools/telemetry/telemetry/page/actions/action_runner.py |
| +++ b/tools/telemetry/telemetry/page/actions/action_runner.py |
| @@ -2,12 +2,15 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +from telemetry.page.actions import page_action |
| from telemetry.page.actions.javascript import JavaScriptAction |
| from telemetry.page.actions.navigate import NavigateAction |
| +from telemetry.page.actions.wait import WaitAction |
| from telemetry.web_perf import timeline_interaction_record as tir_module |
| class ActionRunner(object): |
| + |
| def __init__(self, tab): |
| self._tab = tab |
| @@ -71,6 +74,62 @@ class ActionRunner(object): |
| """ |
| self.RunAction(JavaScriptAction({'expression': js_expression})) |
| + def Wait(self, seconds): |
| + """Wait for the number of seconds specified. |
| + |
| + Args: |
| + seconds: The number of seconds to wait. |
| + """ |
| + self.RunAction(WaitAction({'seconds': seconds})) |
| + |
| + def WaitForJavaScriptCondition(self, condition, timeout=60): |
| + """Wait for a JavaScript condition to become true. |
| + |
| + Example: runner.WaitForJavaScriptCondition('window.foo == 10'); |
| + |
| + Args: |
| + condition: The JavaScript condition (as string). |
| + timeout: The timeout in seconds (default to 60). |
| + """ |
| + self.RunAction(WaitAction({'javascript': condition, 'timeout': timeout})) |
| + |
| + def WaitForElement(self, selector=None, contains_text=None, |
| + element_function=None, timeout=60): |
| + """Wait for an element to appear in the document. |
| + |
| + Args: |
| + selector: A CSS selector describing the element. |
| + contains_text: A text that should be appear on the page. |
| + DO NOT SUBMIT: Should this be split out to WaitForText? |
| + element_function: A JavaScript function (as string) that is used |
| + to retrieve the element. For example: |
| + 'function() { return foo.element; }'. |
| + timeout: The timeout in seconds (default to 60). |
| + """ |
| + attr = {'condition': 'element', 'timeout': timeout} |
| + _FillElementSelector( |
| + attr, selector, contains_text, element_function) |
| + self.RunAction(WaitAction(attr)) |
| + |
| + |
| +def _FillElementSelector(attr, selector=None, contains_text=None, |
|
nednguyen
2014/06/06 21:37:51
contains_text -> text & update documentation to ma
chrishenry
2014/06/06 22:50:47
Done.
|
| + element_function=None): |
| + count = 0 |
| + if selector is not None: |
| + count = count + 1 |
| + attr['selector'] = selector |
| + if contains_text is not None: |
| + count = count + 1 |
| + attr['text'] = contains_text |
| + if element_function is not None: |
| + count = count + 1 |
| + attr['element_function'] = element_function |
| + |
| + if count != 1: |
| + raise page_action.PageActionFailed( |
| + 'Must specify 1 way to retrieve function, but %s was specified: %s' % |
| + (len(attr), attr.keys())) |
| + |
| class Interaction(object): |
| def __init__(self, action_runner, label, flags): |