forked from SeleniumHQ/selenium
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1476750
commit b966f72
Showing
13 changed files
with
510 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import interaction | ||
|
||
from .key_input import KeyInput | ||
from .key_actions import KeyActions | ||
from .pointer_input import PointerInput | ||
from .pointer_actions import PointerActions | ||
|
||
from selenium.webdriver.remote.command import Command | ||
|
||
|
||
class ActionBuilder(object): | ||
|
||
def __init__(self, driver, mouse=None, keyboard=None): | ||
if mouse is None: | ||
mouse = PointerInput("mouse", "mouse") | ||
if keyboard is None: | ||
keyboard = KeyInput("keyboard") | ||
self.devices = [keyboard] | ||
self._key_action = KeyActions(keyboard) | ||
self._pointer_action = PointerActions(mouse) | ||
self.driver = driver | ||
|
||
def get_device_with(self, name): | ||
try: | ||
idx = self.devices.index(name) | ||
return self.devices[idx] | ||
except: | ||
pass | ||
|
||
@property | ||
def pointer_inputs(self): | ||
return [device for device in self.devices if device.type == interaction.POINTER] | ||
|
||
@property | ||
def key_inputs(self): | ||
return [device for device in self.devices if device.type == interaction.KEY] | ||
|
||
@property | ||
def key_action(self): | ||
return self._key_action | ||
|
||
@property | ||
def pointer_action(self): | ||
return self._pointer_action | ||
|
||
def add_key_input(self, name): | ||
new_input = KeyInput(name) | ||
self._add_input(new_input) | ||
return new_input | ||
|
||
def add_pointer_input(self, type_, name): | ||
new_input = PointerInput(type_, name) | ||
self._add_input(new_input) | ||
return new_input | ||
|
||
def perform(self): | ||
enc ={"actions": []} | ||
for device in self.devices: | ||
enc["actions"].append(device.encode()) | ||
self.driver.execute(Command.W3C_ACTIONS, enc) | ||
|
||
def clear_actions(self): | ||
self.driver.execute(Command.W3C_CLEAR_ACTIONS) | ||
|
||
def _add_input(self, input): | ||
self.devices.append(input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import uuid | ||
|
||
|
||
class InputDevice(object): | ||
""" | ||
Describes the input device being used for the action. | ||
""" | ||
def __init__(self, name=None): | ||
if name is None: | ||
self.name = uuid.uuid4() | ||
else: | ||
self.name = name | ||
|
||
self.actions = [] | ||
|
||
def add_action(self, action): | ||
""" | ||
""" | ||
self.actions.append(action) | ||
|
||
def clear_actions(self): | ||
self.actions = [] | ||
|
||
def create_pause(self, duraton=0): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
KEY = "key" | ||
POINTER = "pointer" | ||
NONE = "none" | ||
SOURCE_TYPES = set([KEY, POINTER, NONE]) | ||
|
||
|
||
class Interaction(object): | ||
|
||
PAUSE = "pause" | ||
|
||
def __init__(self, source): | ||
self.source = source | ||
|
||
|
||
class Pause(Interaction): | ||
|
||
def __init__(self, source, duration=0): | ||
super(Interaction, self).__init__() | ||
self.source = source | ||
self.duration = duration | ||
|
||
def encode(self): | ||
output = {"type": self.PAUSE} | ||
output["duration"] = self.duration * 1000 | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from ..utils import keys_to_typing | ||
|
||
from .interaction import Interaction | ||
from .key_input import KeyInput | ||
|
||
|
||
class KeyActions(Interaction): | ||
|
||
def __init__(self, source=None): | ||
if source is None: | ||
source = KeyInput() | ||
self.source = source | ||
super(KeyActions, self).__init__(source) | ||
|
||
def key_down(self, letter, element=None): | ||
return self._key_action("create_key_down", | ||
letter, element) | ||
|
||
def key_up(self, letter, element=None): | ||
return self._key_action("create_key_up", | ||
letter, element) | ||
|
||
def pause(self, duration=0): | ||
return self._key_action("create_pause", duration) | ||
|
||
def send_keys(self, text, element=None): | ||
if not isinstance(text, list): | ||
text = keys_to_typing(text) | ||
for letter in text: | ||
self.key_down(letter, element) | ||
self.key_up(letter, element) | ||
return self | ||
|
||
def _key_action(self, action, letter, element=None): | ||
meth = getattr(self.source, action) | ||
meth(letter) | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import interaction | ||
|
||
from input_device import InputDevice | ||
from interaction import (Interaction, | ||
Pause) | ||
|
||
|
||
class KeyInput(InputDevice): | ||
def __init__(self, name): | ||
super(KeyInput, self).__init__() | ||
self.name = name | ||
self.type = interaction.KEY | ||
|
||
def encode(self): | ||
return {"type": self.type, "id": self.name, "actions": [acts.encode() for acts in self.actions]} | ||
|
||
def create_key_down(self, key): | ||
self.add_action(TypingInteraction(self, "keyDown", key)) | ||
|
||
def create_key_up(self, key): | ||
self.add_action(TypingInteraction(self, "keyUp", key)) | ||
|
||
def create_pause(self, pause_duration=0): | ||
self.add_action(Pause(self, pause_duration)) | ||
|
||
|
||
class TypingInteraction(Interaction): | ||
|
||
def __init__(self, source, type_, key): | ||
super(TypingInteraction, self).__init__(source) | ||
self.type = type_ | ||
self.key = key | ||
|
||
def encode(self): | ||
return {"type": self.type, "value": self.key} |
Oops, something went wrong.