Skip to content

Commit 622f3df

Browse files
refactor: Move driver-specific commands to use extensions (part1) (#856)
1 parent 4031de2 commit 622f3df

31 files changed

+606
-239
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ check-all: ## Run all lint checks and unittest
77

88
.PHONY: isort
99
isort: ## Run isort
10-
python -m isort $(ARGS) .
10+
python -m isort --profile black $(ARGS) .
1111

1212
.PHONY: black
1313
black: ## Run black

Pipfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ url = "https://pypi.org/simple"
44
verify_ssl = true
55

66
[dev-packages]
7-
black = "~=22.12.0"
7+
black = "<24.0.0"
88
httpretty = "~=1.1"
9-
isort = "~=5.11"
10-
mypy = "~=1.2"
9+
isort = "<6.0"
10+
mypy = "<2.0"
1111
mock = "~=5.0"
1212
pre-commit = "~=2.21"
1313
pylint = "~=2.17.3"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import TypeVar
16+
17+
from ..protocol import Protocol
18+
19+
T = TypeVar('T')
20+
21+
22+
class CanRememberExtensionPresence(Protocol):
23+
def assert_extension_exists(self: T, ext_name: str) -> T:
24+
...
25+
26+
def mark_extension_absence(self: T, ext_name: str) -> T:
27+
...

appium/webdriver/appium_connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def __init__(
3232
ignore_proxy: Optional[bool] = False,
3333
init_args_for_pool_manager: Union[Dict[str, Any], None] = None,
3434
):
35-
3635
# Need to call before super().__init__ in order to pass arguments for the pool manager in the super.
3736
self._init_args_for_pool_manager = init_args_for_pool_manager or {}
3837

appium/webdriver/extensions/action_helpers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import List, Optional, Tuple, TypeVar
15+
from typing import TYPE_CHECKING, List, Optional, Tuple, cast
1616

1717
from selenium.webdriver.common.action_chains import ActionChains
1818
from selenium.webdriver.common.actions import interaction
1919
from selenium.webdriver.common.actions.action_builder import ActionBuilder
2020
from selenium.webdriver.common.actions.mouse_button import MouseButton
2121
from selenium.webdriver.common.actions.pointer_input import PointerInput
2222

23-
from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
2423
from appium.webdriver.webelement import WebElement
2524

26-
T = TypeVar('T', bound=CanExecuteCommands)
25+
if TYPE_CHECKING:
26+
from appium.webdriver.webdriver import WebDriver
2727

2828

2929
class ActionHelpers:
30-
def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> T:
30+
def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> 'WebDriver':
3131
"""Scrolls from one element to another
3232
3333
Args:
@@ -59,9 +59,9 @@ def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration:
5959
actions.w3c_actions.pointer_action.move_to(destination_el)
6060
actions.w3c_actions.pointer_action.release()
6161
actions.perform()
62-
return self
62+
return cast('WebDriver', self)
6363

64-
def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) -> T:
64+
def drag_and_drop(self, origin_el: WebElement, destination_el: WebElement) -> 'WebDriver':
6565
"""Drag the origin element to the destination element
6666
6767
Args:
@@ -77,9 +77,9 @@ def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) ->
7777
actions.w3c_actions.pointer_action.move_to(destination_el)
7878
actions.w3c_actions.pointer_action.release()
7979
actions.perform()
80-
return self
80+
return cast('WebDriver', self)
8181

82-
def tap(self: T, positions: List[Tuple[int, int]], duration: Optional[int] = None) -> T:
82+
def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None) -> 'WebDriver':
8383
"""Taps on an particular place with up to five fingers, holding for a
8484
certain time
8585
@@ -127,9 +127,9 @@ def tap(self: T, positions: List[Tuple[int, int]], duration: Optional[int] = Non
127127
new_input.create_pause(0.1)
128128
new_input.create_pointer_up(MouseButton.LEFT)
129129
actions.perform()
130-
return self
130+
return cast('WebDriver', self)
131131

132-
def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> T:
132+
def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> 'WebDriver':
133133
"""Swipe from one point to another point, for an optional duration.
134134
135135
Args:
@@ -156,9 +156,9 @@ def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration:
156156
actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
157157
actions.w3c_actions.pointer_action.release()
158158
actions.perform()
159-
return self
159+
return cast('WebDriver', self)
160160

161-
def flick(self: T, start_x: int, start_y: int, end_x: int, end_y: int) -> T:
161+
def flick(self, start_x: int, start_y: int, end_x: int, end_y: int) -> 'WebDriver':
162162
"""Flick from one point to another point.
163163
164164
Args:
@@ -180,4 +180,4 @@ def flick(self: T, start_x: int, start_y: int, end_x: int, end_y: int) -> T:
180180
actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
181181
actions.w3c_actions.pointer_action.release()
182182
actions.perform()
183-
return self
183+
return cast('WebDriver', self)

appium/webdriver/extensions/android/power.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222

2323
class Power(CanExecuteCommands):
24-
2524
AC_OFF, AC_ON = 'off', 'on'
2625

2726
def set_power_capacity(self: T, percent: int) -> T:

0 commit comments

Comments
 (0)