Sitelet https://github.com/appium/python-client/pull/739/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appium/options/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self) -> None:
# FIXME: https://github.com/SeleniumHQ/selenium/issues/10755
self._ignore_local_proxy = False

def set_capability(self, name: str, value: Any) -> T:
def set_capability(self: T, name: str, value: Any) -> T:
w3c_name = name if name in self.W3C_CAPABILITY_NAMES or ':' in name else f'{APPIUM_PREFIX}{name}'
if value is None:
if w3c_name in self._caps:
Expand All @@ -80,7 +80,7 @@ def get_capability(self, name: str) -> Any:
"""Fetches capability value or None if the capability is not set"""
return self._caps[name] if name in self._caps else self._caps.get(f'{APPIUM_PREFIX}{name}')

def load_capabilities(self, caps: Dict[str, Any]) -> T:
def load_capabilities(self: T, caps: Dict[str, Any]) -> T:
"""Sets multiple capabilities"""
for name, value in caps.items():
self.set_capability(name, value)
Expand Down
26 changes: 13 additions & 13 deletions appium/webdriver/extensions/action_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING, List, Optional, Tuple
from typing import List, Optional, Tuple, TypeVar

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.mouse_button import MouseButton
from selenium.webdriver.common.actions.pointer_input import PointerInput

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.webelement import WebElement

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class ActionHelpers:
def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> 'WebDriver':
def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> T:
"""Scrolls from one element to another

Args:
Expand Down Expand Up @@ -68,9 +68,9 @@ def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Op
actions.w3c_actions.pointer_action.move_to_location(dest_el_rect['x'], dest_el_rect['y'])
actions.w3c_actions.pointer_action.release()
actions.perform()
return self # type: ignore
return self

def drag_and_drop(self, origin_el: WebElement, destination_el: WebElement) -> 'WebDriver':
def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) -> T:
"""Drag the origin element to the destination element

Args:
Expand All @@ -86,9 +86,9 @@ def drag_and_drop(self, origin_el: WebElement, destination_el: WebElement) -> 'W
actions.w3c_actions.pointer_action.move_to(destination_el)
actions.w3c_actions.pointer_action.release()
actions.perform()
return self # type: ignore
return self

def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None) -> 'WebDriver':
def tap(self: T, positions: List[Tuple[int, int]], duration: Optional[int] = None) -> T:
"""Taps on an particular place with up to five fingers, holding for a
certain time

Expand Down Expand Up @@ -136,9 +136,9 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
new_input.create_pause(0.1)
new_input.create_pointer_up(MouseButton.LEFT)
actions.perform()
return self # type: ignore
return self

def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> 'WebDriver':
def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> T:
"""Swipe from one point to another point, for an optional duration.

Args:
Expand All @@ -162,9 +162,9 @@ def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: in
actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
actions.w3c_actions.pointer_action.release()
actions.perform()
return self # type: ignore
return self

def flick(self, start_x: int, start_y: int, end_x: int, end_y: int) -> 'WebDriver':
def flick(self: T, start_x: int, start_y: int, end_x: int, end_y: int) -> T:
"""Flick from one point to another point.

Args:
Expand All @@ -186,4 +186,4 @@ def flick(self, start_x: int, start_y: int, end_x: int, end_y: int) -> 'WebDrive
actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
actions.w3c_actions.pointer_action.release()
actions.perform()
return self # type: ignore
return self
9 changes: 4 additions & 5 deletions appium/webdriver/extensions/android/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING
from typing import TypeVar

from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.mobilecommand import MobileCommand as Command

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class Activities(CanExecuteCommands):
def start_activity(self, app_package: str, app_activity: str, **opts: str) -> 'WebDriver':
def start_activity(self: T, app_package: str, app_activity: str, **opts: str) -> T:
"""Opens an arbitrary activity during a test. If the activity belongs to
another application, that application is started and the activity is opened.

Expand Down Expand Up @@ -58,7 +57,7 @@ def start_activity(self, app_package: str, app_activity: str, **opts: str) -> 'W
if key in opts:
data[value] = opts[key]
self.execute(Command.START_ACTIVITY, data)
return self # type: ignore
return self

@property
def current_activity(self) -> str:
Expand Down
9 changes: 4 additions & 5 deletions appium/webdriver/extensions/android/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING, Any
from typing import Any, TypeVar

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.mobilecommand import MobileCommand as Command

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class Common(CanExecuteCommands):
Expand All @@ -41,14 +40,14 @@ def end_test_coverage(self, intent: str, path: str) -> Any: # TODO Check return
}
return self.execute(Command.END_TEST_COVERAGE, data)['value']

def open_notifications(self) -> 'WebDriver':
def open_notifications(self: T) -> T:
"""Open notification shade in Android (API Level 18 and above)

Returns:
Union['WebDriver', 'Common']: Self instance
"""
self.execute(Command.OPEN_NOTIFICATIONS, {})
return self # type: ignore
return self

@property
def current_package(self) -> str:
Expand Down
17 changes: 8 additions & 9 deletions appium/webdriver/extensions/android/gsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING
from typing import TypeVar

from appium.common.helper import extract_const_attributes
from appium.common.logger import logger
from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.mobilecommand import MobileCommand as Command

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class GsmCallActions:
Expand Down Expand Up @@ -49,7 +48,7 @@ class GsmVoiceState:


class Gsm(CanExecuteCommands):
def make_gsm_call(self, phone_number: str, action: str) -> 'WebDriver':
def make_gsm_call(self: T, phone_number: str, action: str) -> T:
"""Make GSM call (Emulator only)

Android only.
Expand All @@ -72,9 +71,9 @@ def make_gsm_call(self, phone_number: str, action: str) -> 'WebDriver':
f'(e.g. {GsmCallActions.__name__}.CALL)'
)
self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action})
return self # type: ignore
return self

def set_gsm_signal(self, strength: int) -> 'WebDriver':
def set_gsm_signal(self: T, strength: int) -> T:
"""Set GSM signal strength (Emulator only)

Android only.
Expand All @@ -96,9 +95,9 @@ def set_gsm_signal(self, strength: int) -> 'WebDriver':
f'(e.g. {GsmSignalStrength.__name__}.GOOD)'
)
self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength})
return self # type: ignore
return self

def set_gsm_voice(self, state: str) -> 'WebDriver':
def set_gsm_voice(self: T, state: str) -> T:
"""Set GSM voice state (Emulator only)

Android only.
Expand All @@ -120,7 +119,7 @@ def set_gsm_voice(self, state: str) -> 'WebDriver':
f'(e.g. {GsmVoiceState.__name__}.HOME)'
)
self.execute(Command.SET_GSM_VOICE, {'state': state})
return self # type: ignore
return self

def _add_commands(self) -> None:
# noinspection PyProtectedMember,PyUnresolvedReferences
Expand Down
13 changes: 6 additions & 7 deletions appium/webdriver/extensions/android/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING
from typing import TypeVar

from appium.common.helper import extract_const_attributes
from appium.common.logger import logger
from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.mobilecommand import MobileCommand as Command

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class NetSpeed:
Expand Down Expand Up @@ -75,16 +74,16 @@ def set_network_connection(self, connection_type: int) -> int:
data = {'parameters': {'type': connection_type}}
return self.execute(Command.SET_NETWORK_CONNECTION, data)['value']

def toggle_wifi(self) -> 'WebDriver':
def toggle_wifi(self: T) -> T:
"""Toggle the wifi on the device, Android only.

Returns:
Union['WebDriver', 'Network']: Self instance
"""
self.execute(Command.TOGGLE_WIFI, {})
return self # type: ignore
return self

def set_network_speed(self, speed_type: str) -> 'WebDriver':
def set_network_speed(self: T, speed_type: str) -> T:
"""Set the network speed emulation.

Android Emulator only.
Expand All @@ -107,7 +106,7 @@ def set_network_speed(self, speed_type: str) -> 'WebDriver':
)

self.execute(Command.SET_NETWORK_SPEED, {'netspeed': speed_type})
return self # type: ignore
return self

def _add_commands(self) -> None:
# noinspection PyProtectedMember,PyUnresolvedReferences
Expand Down
13 changes: 6 additions & 7 deletions appium/webdriver/extensions/android/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING
from typing import TypeVar

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.mobilecommand import MobileCommand as Command

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class Power(CanExecuteCommands):

AC_OFF, AC_ON = 'off', 'on'

def set_power_capacity(self, percent: int) -> 'WebDriver':
def set_power_capacity(self: T, percent: int) -> T:
"""Emulate power capacity change on the connected emulator.

Android only.
Expand All @@ -40,9 +39,9 @@ def set_power_capacity(self, percent: int) -> 'WebDriver':
Union['WebDriver', 'Power']: Self instance
"""
self.execute(Command.SET_POWER_CAPACITY, {'percent': percent})
return self # type: ignore
return self

def set_power_ac(self, ac_state: str) -> 'WebDriver':
def set_power_ac(self: T, ac_state: str) -> T:
"""Emulate power state change on the connected emulator.

Android only.
Expand All @@ -58,7 +57,7 @@ def set_power_ac(self, ac_state: str) -> 'WebDriver':
Union['WebDriver', 'Power']: Self instance
"""
self.execute(Command.SET_POWER_AC, {'state': ac_state})
return self # type: ignore
return self

def _add_commands(self) -> None:
# noinspection PyProtectedMember,PyUnresolvedReferences
Expand Down
9 changes: 4 additions & 5 deletions appium/webdriver/extensions/android/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING
from typing import TypeVar

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.webdriver.mobilecommand import MobileCommand as Command

if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
T = TypeVar('T', bound=CanExecuteCommands)


class Sms(CanExecuteCommands):
def send_sms(self, phone_number: str, message: str) -> 'WebDriver':
def send_sms(self: T, phone_number: str, message: str) -> T:
"""Emulate send SMS event on the connected emulator.

Android only.
Expand All @@ -38,7 +37,7 @@ def send_sms(self, phone_number: str, message: str) -> 'WebDriver':
Union['WebDriver', 'Sms']: Self instance
"""
self.execute(Command.SEND_SMS, {'phoneNumber': phone_number, 'message': message})
return self # type: ignore
return self

def _add_commands(self) -> None:
# noinspection PyProtectedMember,PyUnresolvedReferences
Expand Down
Loading