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 579e7335a5f77f36db5d892aa6967bd6d5684dc1..02967f8fb9bef8070285658583a5015bed7c5ec4 100644 |
--- a/tools/telemetry/telemetry/page/actions/action_runner.py |
+++ b/tools/telemetry/telemetry/page/actions/action_runner.py |
@@ -4,7 +4,9 @@ |
from telemetry.page.actions import page_action |
from telemetry.page.actions.javascript import JavaScriptAction |
+from telemetry.page.actions.javascript_click import ClickElementAction |
from telemetry.page.actions.navigate import NavigateAction |
+from telemetry.page.actions.tap import TapAction |
from telemetry.page.actions.wait import WaitAction |
from telemetry.web_perf import timeline_interaction_record as tir_module |
@@ -69,15 +71,35 @@ class ActionRunner(object): |
self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() |
def ExecuteJavaScript(self, js_expression): |
- """Executes a given JavaScript expression. |
+ """Executes a given JavaScript expression. Does not return the result. |
Example: runner.ExecuteJavaScript('var foo = 1;'); |
Args: |
js_expression: The expression to execute (provided as string). |
+ |
+ Raises: |
+ EvaluationException: The statement failed to execute. |
""" |
self.RunAction(JavaScriptAction({'expression': js_expression})) |
+ def EvaluateJavaScript(self, expression): |
+ """Returns the evaluation result of the given JavaScript expression. |
+ |
+ The evaluation results must be convertible to JSON. If the result |
+ is not needed, use ExecuteJavaScript instead. |
+ |
+ Example: num = runner.EvaluateJavaScript('document.location.href') |
+ |
+ Args: |
+ expression: The expression to evaluate (provided as string). |
+ |
+ Raises: |
+ EvaluationException: The statement expression failed to execute |
+ or the evaluation result can not be JSON-ized. |
+ """ |
+ return self._tab.EvaluateJavaScript(expression) |
+ |
def Wait(self, seconds): |
"""Wait for the number of seconds specified. |
@@ -99,8 +121,10 @@ class ActionRunner(object): |
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. |
+ """Wait for an element to appear in the document. |
+ |
+ The element may be selected via selector, text, or element_function. |
+ Only one of these arguments must be specified. |
Args: |
selector: A CSS selector describing the element. |
@@ -115,6 +139,40 @@ class ActionRunner(object): |
attr, selector, text, element_function) |
self.RunAction(WaitAction(attr)) |
+ def TapElement(self, selector=None, text=None, element_function=None): |
+ """Tap an element. |
+ |
+ The element may be selected via selector, text, or element_function. |
+ Only one of these arguments 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; }'. |
+ """ |
+ attr = {'automatically_record_interaction': False} |
+ _FillElementSelector(attr, selector, text, element_function) |
+ self.RunAction(TapAction(attr)) |
+ |
+ def ClickElement(self, selector=None, text=None, element_function=None): |
+ """Click an element. |
+ |
+ The element may be selected via selector, text, or element_function. |
+ Only one of these arguments 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; }'. |
+ """ |
+ attr = {'automatically_record_interaction': False} |
+ _FillElementSelector(attr, selector, text, element_function) |
+ self.RunAction(ClickElementAction(attr)) |
+ |
def _FillElementSelector(attr, selector=None, text=None, element_function=None): |
count = 0 |