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 66a02bbc6c17fc5b32b449d441137bdb6f8a7ce6..e937c315e11761457337f6b1339c65802eacbc09 100644 |
--- a/tools/telemetry/telemetry/page/actions/action_runner.py |
+++ b/tools/telemetry/telemetry/page/actions/action_runner.py |
@@ -3,7 +3,9 @@ |
# found in the LICENSE file. |
from telemetry.page.actions import page_action |
+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 |
@@ -46,6 +48,27 @@ class ActionRunner(object): |
interaction.Begin() |
return interaction |
+ def BeginGestureInteraction( |
+ self, label, is_smooth=False, is_responsive=False): |
+ """Marks the beginning of a gesture-based interaction record. |
+ |
+ This is similar to normal interaction record, but it will |
+ auto-narrow the interaction time period to only include the |
+ synthetic gesture event output by Chrome. This is typically use to |
+ reduce noise in gesture-based analysis (e.g., analysis for a |
+ swipe/scroll). |
+ |
+ The interaction record label will be prepended with 'Gesture_'. |
+ |
+ Args: |
+ label: A label for this particular interaction. This can be any |
+ user-defined string, but must not contain '/'. |
+ is_smooth: Whether to check for smoothness metrics for this interaction. |
+ is_responsive: Whether to check for responsiveness metrics for |
+ this interaction. |
+ """ |
+ return self.BeginInteraction('Gesture_' + label, is_smooth, is_responsive) |
+ |
def NavigateToPage(self, page, timeout_seconds=None): |
""" Navigate to the given page. |
@@ -68,15 +91,35 @@ class ActionRunner(object): |
self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() |
def ExecuteJavaScript(self, statement): |
- """Executes a given JavaScript statement. |
+ """Executes a given JavaScript expression. Does not return the result. |
Example: runner.ExecuteJavaScript('var foo = 1;'); |
Args: |
statement: The statement to execute (provided as string). |
+ |
+ Raises: |
+ EvaluationException: The statement failed to execute. |
""" |
self._tab.ExecuteJavaScript(statement) |
+ 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. |
@@ -98,8 +141,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. |
@@ -114,6 +159,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 |