mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 11:45:37 +00:00
Bug 1328726 - (wdclient) Add actions endpoints, key actions API; r=ato
MozReview-Commit-ID: CScEEaAgw0X --HG-- extra : rebase_source : bfaab0bb11459930c88089bba6f1f98088456a0b
This commit is contained in:
parent
320a29e888
commit
381461a76f
@ -70,6 +70,101 @@ class Timeouts(object):
|
||||
self._implicit_wait = value
|
||||
|
||||
|
||||
class ActionSequence(object):
|
||||
"""API for creating and performing action sequences.
|
||||
|
||||
Each action method adds one or more actions to a queue. When perform()
|
||||
is called, the queued actions fire in order.
|
||||
|
||||
May be chained together as in::
|
||||
|
||||
ActionSequence(session, "key", id) \
|
||||
.key_down("a") \
|
||||
.key_up("a") \
|
||||
.perform()
|
||||
"""
|
||||
def __init__(self, session, action_type, input_id):
|
||||
"""Represents a sequence of actions of one type for one input source.
|
||||
|
||||
:param session: WebDriver session.
|
||||
:param action_type: Action type; may be "none", "key", or "pointer".
|
||||
:param input_id: ID of input source.
|
||||
"""
|
||||
self.session = session
|
||||
# TODO take advantage of remote end generating uuid
|
||||
self._id = input_id
|
||||
self._type = action_type
|
||||
self._actions = []
|
||||
|
||||
@property
|
||||
def dict(self):
|
||||
return {
|
||||
"type": self._type,
|
||||
"id": self._id,
|
||||
"actions": self._actions,
|
||||
}
|
||||
|
||||
@command
|
||||
def perform(self):
|
||||
"""Perform all queued actions."""
|
||||
self.session.actions.perform([self.dict])
|
||||
|
||||
def _key_action(self, subtype, value):
|
||||
self._actions.append({"type": subtype, "value": value})
|
||||
|
||||
def key_up(self, value):
|
||||
"""Queue a keyUp action for `value`.
|
||||
|
||||
:param value: Character to perform key action with.
|
||||
"""
|
||||
self._key_action("keyUp", value)
|
||||
return self
|
||||
|
||||
def key_down(self, value):
|
||||
"""Queue a keyDown action for `value`.
|
||||
|
||||
:param value: Character to perform key action with.
|
||||
"""
|
||||
self._key_action("keyDown", value)
|
||||
return self
|
||||
|
||||
def send_keys(self, keys):
|
||||
"""Queue a keyDown and keyUp action for each character in `keys`.
|
||||
|
||||
:param keys: String of keys to perform key actions with.
|
||||
"""
|
||||
for c in keys:
|
||||
self.key_down(c)
|
||||
self.key_up(c)
|
||||
return self
|
||||
|
||||
|
||||
class Actions(object):
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
|
||||
@command
|
||||
def perform(self, actions=None):
|
||||
"""Performs actions by tick from each action sequence in `actions`.
|
||||
|
||||
:param actions: List of input source action sequences. A single action
|
||||
sequence may be created with the help of
|
||||
``ActionSequence.dict``.
|
||||
"""
|
||||
body = {"actions": [] if actions is None else actions}
|
||||
return self.session.send_command("POST", "actions", body)
|
||||
|
||||
@command
|
||||
def release(self):
|
||||
return self.session.send_command("DELETE", "actions")
|
||||
|
||||
def sequence(self, *args, **kwargs):
|
||||
"""Return an empty ActionSequence of the designated type.
|
||||
|
||||
See ActionSequence for parameter list.
|
||||
"""
|
||||
return ActionSequence(self.session, *args, **kwargs)
|
||||
|
||||
class Window(object):
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
@ -190,6 +285,7 @@ class Session(object):
|
||||
self.window = Window(self)
|
||||
self.find = Find(self)
|
||||
self.alert = UserPrompt(self)
|
||||
self.actions = Actions(self)
|
||||
|
||||
def __enter__(self):
|
||||
self.start()
|
||||
|
Loading…
Reference in New Issue
Block a user