telemetry.page.action_runner | index telemetry/page/action_runner.py

`# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.`

Modules
`` |  |

logging | time | telemetry.web_perf.timeline_interaction_record | urlparse

Classes
`` |  |

__builtin__.object
  ActionRunner
  Interaction

class ActionRunner(__builtin__.object)
`` |  | Methods defined here:

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; })()'.`

CreateGestureInteraction(self, label, repeatable=False)
  `Create an action.Interaction object that issues 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_'.
  e.g:
  with action_runner.CreateGestureInteraction('Scroll-1'):
  action_runner.ScrollPage()
  Args:
  label: A label for this particular interaction. This can be any
  user-defined string, but must not contain '/'.
  repeatable: Whether other interactions may use the same logical name
  as this interaction. All interactions with the same logical name must
  have the same flags.
  Returns:
  An instance of action_runner.Interaction`

CreateInteraction(self, label, repeatable=False)
  `Create an action.Interaction object that issues interaction record.
  An interaction record is a labeled time period containing
  interaction that developers care about. Each set of metrics
  specified in flags will be calculated for this time period.
  To mark the start of interaction record, call Begin() method on the returned
  object. To mark the finish of interaction record, call End() method on
  it. Or better yet, use the with statement to create an
  interaction record that covers the actions in the with block.
  e.g:
  with action_runner.CreateInteraction('Animation-1'):
  action_runner.TapElement(...)
  action_runner.WaitForJavaScriptCondition(...)
  Args:
  label: A label for this particular interaction. This can be any
  user-defined string, but must not contain '/'.
  repeatable: Whether other interactions may use the same logical name
  as this interaction. All interactions with the same logical name must
  have the same flags.
  Returns:
  An instance of action_runner.Interaction`

DragPage(self, left_start_ratio, top_start_ratio, left_end_ratio, top_end_ratio, speed_in_pixels_per_second=800, use_touch=False, selector=None, text=None, element_function=None)
  `Perform a drag gesture on the page.
  You should specify a start and an end point in ratios of page width and
  height (see drag.js for full implementation).
  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.
  left_end_ratio: The horizontal ending coordinate of the
  gesture, as a ratio of the visible bounding rectangle for
  document.body.
  top_end_ratio: The vertical ending coordinate of the
  gesture, as a ratio of the visible bounding rectangle for
  document.body.
  speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
  use_touch: Whether dragging should be done with touch input.`

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.`

ExecuteJavaScript(self, 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.`

ForceGarbageCollection(self)
  `Forces JavaScript garbage collection on the page.`

LoadMedia(self, selector=None, event_timeout_in_seconds=0, event_to_await='canplaythrough')
  `Invokes load() on media elements and awaits an event.
  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.
  event_timeout_in_seconds: Maximum waiting time for the event to be fired.
  0 means do not wait.
  event_to_await: Which event to await. For example: 'canplaythrough' or
  'loadedmetadata'.
  Raises:
  TimeoutException: If the maximum waiting time is exceeded.`

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.`

MouseClick(self, selector=None)
  `Mouse click the given element.
  Args:
  selector: A CSS selector describing the element.`

Navigate(self, url, script_to_evaluate_on_commit=None, timeout_in_seconds=60)
  `Navigates to url.
  If |script_to_evaluate_on_commit| is given, the script source string will be
  evaluated when the navigation is committed. This is after the context of
  the page exists, but before any script on the page itself has executed.`

PauseInteractive(self)
  `Pause the page execution and wait for terminal interaction.
  This is typically used for debugging. You can use this to pause
  the page execution and inspect the browser state before
  continuing.`

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).`

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).`

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.`

ReloadPage(self)
  `Reloads the page.`

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.`

RepeatableBrowserDrivenScroll(self, x_scroll_distance_ratio=0.0, y_scroll_distance_ratio=0.5, repeat_count=0, repeat_delay_ms=250)
  `Perform a browser driven repeatable scroll gesture.
  The scroll gesture is driven from the browser, this is useful because the
  main thread often isn't resposive but the browser process usually is, so the
  delay between the scroll gestures should be consistent.
  Args:
  x_scroll_distance_ratio: The horizontal lenght of the scroll as a fraction
  of the screen width.
  y_scroll_distance_ratio: The vertical lenght of the scroll as a fraction
  of the screen height.
  repeat_count: The number of additional times to repeat the gesture.
  repeat_delay_ms: The delay in milliseconds between each scroll gesture.`

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', 'down', 'upleft', 'upright', 'downleft', or 'downright'
  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).`

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', 'down', 'upleft', 'upright', 'downleft', or 'downright'
  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).`

ScrollElement(self, selector=None, text=None, element_function=None, 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, synthetic_gesture_source='DEFAULT')
  `Perform scroll gesture on the element.
  The element may be selected via selector, text, or element_function.
  Only one of these arguments must be specified.
  You may specify distance or distance_expr, but not both. If
  neither is specified, the default scroll distance is variable
  depending on direction (see scroll.js for full implementation).
  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
  the element.
  top_start_ratio: The vertical starting coordinate of the
  gesture, as a ratio of the visible bounding rectangle for
  the element.
  direction: The direction of scroll, either 'left', 'right',
  'up', 'down', 'upleft', 'upright', 'downleft', or 'downright'
  distance: The distance to scroll (in pixel).
  distance_expr: A JavaScript expression (as string) that can be
  evaluated to compute scroll distance. Example:
  'window.scrollTop' or '(function() { return crazyMath(); })()'.
  speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
  use_touch: Whether scrolling should be done with touch input.
  synthetic_gesture_source: the source input device type for the
  synthetic gesture: 'DEFAULT', 'TOUCH' or 'MOUSE'.`

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, synthetic_gesture_source='DEFAULT')
  `Perform scroll gesture on the page.
  You may specify distance or distance_expr, but not both. If
  neither is specified, the default scroll distance is variable
  depending on direction (see scroll.js for full implementation).
  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', 'down', 'upleft', 'upright', 'downleft', or 'downright'
  distance: The distance to scroll (in pixel).
  distance_expr: A JavaScript expression (as string) that can be
  evaluated to compute scroll distance. Example:
  'window.scrollTop' or '(function() { return crazyMath(); })()'.
  speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
  use_touch: Whether scrolling should be done with touch input.
  synthetic_gesture_source: the source input device type for the
  synthetic gesture: 'DEFAULT', 'TOUCH' or 'MOUSE'.`

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.`

SwipeElement(self, selector=None, text=None, element_function=None, 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 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; }'.
  left_start_ratio: The horizontal starting coordinate of the
  gesture, as a ratio of the visible bounding rectangle for
  the element.
  top_start_ratio: The vertical starting coordinate of the
  gesture, as a ratio of the visible bounding rectangle for
  the element.
  direction: The direction of swipe, either 'left', 'right',
  'up', or 'down'
  distance: The distance to swipe (in pixel).
  speed_in_pixels_per_second: The speed of the gesture (in pixels/s).`

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.
  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 swipe, either 'left', 'right',
  'up', or 'down'
  distance: The distance to swipe (in pixel).
  speed_in_pixels_per_second: The speed of the gesture (in pixels/s).`

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; })()'.`

Wait(self, seconds)
  `Wait for the number of seconds specified.
  Args:
  seconds: The number of seconds to wait.`

WaitForElement(self, selector=None, text=None, element_function=None, timeout_in_seconds=60)
  `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.
  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_in_seconds: The timeout in seconds (default to 60).`

WaitForJavaScriptCondition(self, condition, timeout_in_seconds=60)
  `Wait for a JavaScript condition to become true.
  Example: runner.WaitForJavaScriptCondition('window.foo == 10');
  Args:
  condition: The JavaScript condition (as string).
  timeout_in_seconds: The timeout in seconds (default to 60).`

WaitForNavigate(self, timeout_in_seconds_seconds=60)

__init__(self, tab, skip_waits=False)

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

tab
  `Returns the tab on which actions are performed.`

class Interaction(__builtin__.object)
`` |  | Methods defined here:

Begin(self)

End(self)

__enter__(self)

__exit__(self, exc_type, exc_value, traceback)

__init__(self, action_runner, label, flags)

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

Data
`` |  | GESTURE_SOURCE_DEFAULT = 'DEFAULT' SUPPORTED_GESTURE_SOURCES = ('DEFAULT', 'MOUSE', 'TOUCH')