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

Unified Diff: telemetry/telemetry/internal/actions/action_runner.py

Issue 2122703002: [telemetry] Add support for dispatching key events (Closed) Base URL: git@github.com:catapult-project/catapult.git@master
Patch Set: Raise explicit ValueError Created 4 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
« no previous file with comments | « no previous file | telemetry/telemetry/internal/actions/action_runner_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/actions/action_runner.py
diff --git a/telemetry/telemetry/internal/actions/action_runner.py b/telemetry/telemetry/internal/actions/action_runner.py
index 19dc78ec1782fc15c6f2a0e5d9c124e66b983a61..ebb61f7c5d7caeb765f62b59c5d31a01717aa33f 100644
--- a/telemetry/telemetry/internal/actions/action_runner.py
+++ b/telemetry/telemetry/internal/actions/action_runner.py
@@ -8,6 +8,7 @@ import urlparse
from telemetry.internal.actions.drag import DragAction
from telemetry.internal.actions.javascript_click import ClickElementAction
+from telemetry.internal.actions.key_event import KeyPressAction
from telemetry.internal.actions.load_media import LoadMediaAction
from telemetry.internal.actions.loop import LoopAction
from telemetry.internal.actions.mouse_click import MouseClickAction
@@ -567,6 +568,31 @@ class ActionRunner(object):
direction=direction, distance=distance,
speed_in_pixels_per_second=speed_in_pixels_per_second))
+ def PressKey(self, key, repeat_count=1, repeat_delay_ms=100, timeout=60):
+ """Perform a key press.
+
+ Args:
+ key: DOM value of the pressed key (e.g. 'PageDown', see
+ https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
+ repeat_count: How many times the key should be pressed.
+ repeat_delay_ms: Delay after each keypress (including the last one) in
+ milliseconds.
+ """
+ for _ in xrange(repeat_count):
+ self._RunAction(KeyPressAction(key, timeout=timeout))
+ self.Wait(repeat_delay_ms / 1000.0)
+
+ def EnterText(self, text, character_delay_ms=100, timeout=60):
+ """Enter text by performing key presses.
+
+ Args:
+ text: The text to enter.
+ character_delay_ms: Delay after each keypress (including the last one) in
+ milliseconds.
+ """
+ for c in text:
+ self.PressKey(c, repeat_delay_ms=character_delay_ms, timeout=timeout)
+
def LoadMedia(self, selector=None, event_timeout_in_seconds=0,
event_to_await='canplaythrough'):
"""Invokes load() on media elements and awaits an event.
« no previous file with comments | « no previous file | telemetry/telemetry/internal/actions/action_runner_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698