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

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

Issue 346923003: Add ActionRunner wrapper for the remaining less used actions (try 2): (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update unit test to skip test if touch is not supported. Created 6 years, 5 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 d81c5b3acc07d0a0d5f544ee18af73387b00a0e7..b63a904671cf1f93acd1f56907df6b6230210cce 100644
--- a/tools/telemetry/telemetry/page/actions/action_runner.py
+++ b/tools/telemetry/telemetry/page/actions/action_runner.py
@@ -5,8 +5,15 @@
import time
from telemetry.page.actions.javascript_click import ClickElementAction
+from telemetry.page.actions.loop import LoopAction
from telemetry.page.actions.navigate import NavigateAction
+from telemetry.page.actions.pinch import PinchAction
+from telemetry.page.actions.play import PlayAction
+from telemetry.page.actions.repaint_continuously import (
+ RepaintContinuouslyAction)
from telemetry.page.actions.scroll import ScrollAction
+from telemetry.page.actions.scroll_bounce import ScrollBounceAction
+from telemetry.page.actions.seek import SeekAction
from telemetry.page.actions.swipe import SwipeAction
from telemetry.page.actions.tap import TapAction
from telemetry.page.actions.wait import WaitForElementAction
@@ -72,7 +79,7 @@ class ActionRunner(object):
return self.BeginInteraction('Gesture_' + label, is_smooth, is_responsive)
def NavigateToPage(self, page, timeout_in_seconds=60):
- """ Navigate to the given page.
+ """Navigate to the given page.
Args:
page: page is an instance of page.Page
@@ -91,6 +98,11 @@ class ActionRunner(object):
self._tab.WaitForNavigate(timeout_in_seconds_seconds)
self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
+ def ReloadPage(self):
+ """Reloads the page."""
+ self._tab.ExecuteJavaScript('window.location.reload()')
+ self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
+
def ExecuteJavaScript(self, statement):
"""Executes a given JavaScript expression. Does not return the result.
@@ -191,6 +203,63 @@ class ActionRunner(object):
self.RunAction(ClickElementAction(
selector=selector, text=text, element_function=element_function))
+ def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5,
+ scale_factor=None, speed_in_pixels_per_second=800):
+ """Perform the pinch gesture on the page.
+
+ It computes the pinch gesture automatically based on the anchor
+ coordinate and the scale factor. The scale factor is the ratio of
+ of the final span and the initial span of the gesture.
+
+ Args:
+ left_anchor_ratio: The horizontal pinch anchor coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ document.body.
+ top_anchor_ratio: The vertical pinch anchor coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ document.body.
+ scale_factor: The ratio of the final span to the initial span.
+ The default scale factor is
+ 3.0 / (window.outerWidth/window.innerWidth).
+ speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
+ """
+ self.RunAction(PinchAction(
+ left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio,
+ scale_factor=scale_factor,
+ speed_in_pixels_per_second=speed_in_pixels_per_second))
+
+ def PinchElement(self, selector=None, text=None, element_function=None,
+ left_anchor_ratio=0.5, top_anchor_ratio=0.5,
+ scale_factor=None, speed_in_pixels_per_second=800):
+ """Perform the pinch gesture on an element.
+
+ It computes the pinch gesture automatically based on the anchor
+ coordinate and the scale factor. The scale factor is the ratio of
+ of the final span and the initial span of the gesture.
+
+ 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; }'.
+ left_anchor_ratio: The horizontal pinch anchor coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ the element.
+ top_anchor_ratio: The vertical pinch anchor coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ the element.
+ scale_factor: The ratio of the final span to the initial span.
+ The default scale factor is
+ 3.0 / (window.outerWidth/window.innerWidth).
+ speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
+ """
+ self.RunAction(PinchAction(
+ selector=selector, text=text, element_function=element_function,
+ left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio,
+ scale_factor=scale_factor,
+ speed_in_pixels_per_second=speed_in_pixels_per_second))
+
def ScrollPage(self, left_start_ratio=0.5, top_start_ratio=0.5,
direction='down', distance=None, distance_expr=None,
speed_in_pixels_per_second=800, use_touch=False):
@@ -263,6 +332,77 @@ class ActionRunner(object):
speed_in_pixels_per_second=speed_in_pixels_per_second,
use_touch=use_touch))
+ def ScrollBouncePage(self, left_start_ratio=0.5, top_start_ratio=0.5,
+ direction='down', distance=100,
+ overscroll=10, repeat_count=10,
+ speed_in_pixels_per_second=400):
+ """Perform scroll bounce gesture on the page.
+
+ This gesture scrolls the page by the number of pixels specified in
+ distance, in the given direction, followed by a scroll by
+ (distance + overscroll) pixels in the opposite direction.
+ The above gesture is repeated repeat_count times.
+
+ Args:
+ left_start_ratio: The horizontal starting coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ document.body.
+ top_start_ratio: The vertical starting coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ document.body.
+ direction: The direction of scroll, either 'left', 'right',
+ 'up', or 'down'
+ distance: The distance to scroll (in pixel).
+ overscroll: The number of additional pixels to scroll back, in
+ addition to the givendistance.
+ repeat_count: How often we want to repeat the full gesture.
+ speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
+ """
+ self.RunAction(ScrollBounceAction(
+ left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
+ direction=direction, distance=distance,
+ overscroll=overscroll, repeat_count=repeat_count,
+ speed_in_pixels_per_second=speed_in_pixels_per_second))
+
+ def ScrollBounceElement(self, selector=None, text=None, element_function=None,
+ left_start_ratio=0.5, top_start_ratio=0.5,
+ direction='down', distance=100,
+ overscroll=10, repeat_count=10,
+ speed_in_pixels_per_second=400):
+ """Perform scroll bounce gesture on the element.
+
+ This gesture scrolls on the element by the number of pixels specified in
+ distance, in the given direction, followed by a scroll by
+ (distance + overscroll) pixels in the opposite direction.
+ The above gesture is repeated repeat_count times.
+
+ 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; }'.
+ left_start_ratio: The horizontal starting coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ document.body.
+ top_start_ratio: The vertical starting coordinate of the
+ gesture, as a ratio of the visible bounding rectangle for
+ document.body.
+ direction: The direction of scroll, either 'left', 'right',
+ 'up', or 'down'
+ distance: The distance to scroll (in pixel).
+ overscroll: The number of additional pixels to scroll back, in
+ addition to the givendistance.
+ repeat_count: How often we want to repeat the full gesture.
+ speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
+ """
+ self.RunAction(ScrollBounceAction(
+ selector=selector, text=text, element_function=element_function,
+ left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
+ direction=direction, distance=distance,
+ overscroll=overscroll, repeat_count=repeat_count,
+ speed_in_pixels_per_second=speed_in_pixels_per_second))
+
def SwipePage(self, left_start_ratio=0.5, top_start_ratio=0.5,
direction='left', distance=100, speed_in_pixels_per_second=800):
"""Perform swipe gesture on the page.
@@ -316,6 +456,76 @@ class ActionRunner(object):
direction=direction, distance=distance,
speed_in_pixels_per_second=speed_in_pixels_per_second))
+ def PlayMedia(self, selector=None,
+ playing_event_timeout_in_seconds=0,
+ ended_event_timeout_in_seconds=0):
+ """Invokes the "play" action on media elements (such as video).
+
+ Args:
+ selector: A CSS selector describing the element. If none is
+ specified, play the first media element on the page. If the
+ selector matches more than 1 media element, all of them will
+ be played.
+ playing_event_timeout_in_seconds: Maximum waiting time for the "playing"
+ event (dispatched when the media begins to play) to be fired.
+ 0 means do not wait.
+ ended_event_timeout_in_seconds: Maximum waiting time for the "ended"
+ event (dispatched when playback completes) to be fired.
+ 0 means do not wait.
+
+ Raises:
+ TimeoutException: If the maximum waiting time is exceeded.
+ """
+ self.RunAction(PlayAction(
+ selector=selector,
+ playing_event_timeout_in_seconds=playing_event_timeout_in_seconds,
+ ended_event_timeout_in_seconds=ended_event_timeout_in_seconds))
+
+ def SeekMedia(self, seconds, selector=None, timeout_in_seconds=0,
+ log_time=True, label=''):
+ """Performs a seek action on media elements (such as video).
+
+ Args:
+ seconds: The media time to seek to.
+ selector: A CSS selector describing the element. If none is
+ specified, seek the first media element on the page. If the
+ selector matches more than 1 media element, all of them will
+ be seeked.
+ timeout_in_seconds: Maximum waiting time for the "seeked" event
+ (dispatched when the seeked operation completes) to be
+ fired. 0 means do not wait.
+ log_time: Whether to log the seek time for the perf
+ measurement. Useful when performing multiple seek.
+ label: A suffix string to name the seek perf measurement.
+
+ Raises:
+ TimeoutException: If the maximum waiting time is exceeded.
+ """
+ self.RunAction(SeekAction(
+ seconds=seconds, selector=selector,
+ timeout_in_seconds=timeout_in_seconds,
+ log_time=log_time, label=label))
+
+ def LoopMedia(self, loop_count, selector=None, timeout_in_seconds=None):
+ """Loops a media playback.
+
+ Args:
+ loop_count: The number of times to loop the playback.
+ selector: A CSS selector describing the element. If none is
+ specified, loop the first media element on the page. If the
+ selector matches more than 1 media element, all of them will
+ be looped.
+ timeout_in_seconds: Maximum waiting time for the looped playback to
+ complete. 0 means do not wait. None (the default) means to
+ wait loop_count * 60 seconds.
+
+ Raises:
+ TimeoutException: If the maximum waiting time is exceeded.
+ """
+ self.RunAction(LoopAction(
+ loop_count=loop_count, selector=selector,
+ timeout_in_seconds=timeout_in_seconds))
+
def ForceGarbageCollection(self):
"""Forces JavaScript garbage collection on the page."""
self._tab.CollectGarbage()
@@ -329,6 +539,14 @@ class ActionRunner(object):
"""
raw_input("Interacting... Press Enter to continue.")
+ def RepaintContinuously(self, seconds):
+ """Continuously repaints the visible content.
+
+ It does this by requesting animation frames until the given number
+ of seconds have elapsed AND at least three RAFs have been
+ fired. Times out after max(60, self.seconds), if less than three
+ RAFs were fired."""
+ self.RunAction(RepaintContinuouslyAction(seconds=seconds))
class Interaction(object):
« no previous file with comments | « tools/perf/page_sets/tough_video_cases.py ('k') | tools/telemetry/telemetry/page/actions/all_page_actions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698