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

Unified Diff: tools/telemetry/telemetry/page/actions/action_runner.py

Issue 321563003: Add Wait* API to ActionRunner to wrap over WaitAction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing to head. Created 6 years, 6 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
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 084b5ef4c3909d8f7b1960138856c97e48e4d249..579e7335a5f77f36db5d892aa6967bd6d5684dc1 100644
--- a/tools/telemetry/telemetry/page/actions/action_runner.py
+++ b/tools/telemetry/telemetry/page/actions/action_runner.py
@@ -2,8 +2,10 @@
# 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
@@ -76,6 +78,61 @@ 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, text=None, element_function=None,
+ timeout=60):
+ """Wait for an element to appear in the document. Only one of selector,
+ text, or element_function must be specified.
+
+ Args:
+ selector: A CSS selector describing the element.
+ text: The element must contains this exact text.
+ 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, text, element_function)
+ self.RunAction(WaitAction(attr))
+
+
+def _FillElementSelector(attr, selector=None, text=None, element_function=None):
+ count = 0
+ if selector is not None:
+ count = count + 1
+ attr['selector'] = selector
+ if text is not None:
+ count = count + 1
+ attr['text'] = 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):
« no previous file with comments | « tools/perf/page_sets/webrtc_cases.py ('k') | tools/telemetry/telemetry/page/actions/action_runner_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698