Skip to content
Closed
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 .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ jobs:
XCODE_VERSION: 16.4
IOS_VERSION: 18.5
IPHONE_MODEL: iPhone 16
FLUTTER_ANDROID_APP: "https://github.com/AppiumTestDistribution/appium-flutter-server/releases/latest/download/app-debug.apk"
FLUTTER_IOS_APP: "https://github.com/AppiumTestDistribution/appium-flutter-server/releases/latest/download/ios.zip"
FLUTTER_ANDROID_APP: "https://github.com/AppiumTestDistribution/appium-flutter-server/releases/download/0.0.33/app-debug.apk"
FLUTTER_IOS_APP: "https://github.com/AppiumTestDistribution/appium-flutter-server/releases/download/0.0.33/ios.zip"
PREBUILT_WDA_PATH: ${{ github.workspace }}/wda/WebDriverAgentRunner-Runner.app

steps:
Expand Down
55 changes: 9 additions & 46 deletions appium/webdriver/extensions/hw_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@

from typing import Optional

from selenium.common.exceptions import UnknownMethodException
from typing_extensions import Self

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts
from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence

from ..mobilecommand import MobileCommand as Command


class HardwareActions(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence):
class HardwareActions(CanExecuteCommands, CanExecuteScripts):
def lock(self, seconds: Optional[int] = None) -> Self:
"""Lock the device. No changes are made if the device is already unlocked.

Expand All @@ -39,11 +35,7 @@ def lock(self, seconds: Optional[int] = None) -> Self:
"""
ext_name = 'mobile: lock'
args = {'seconds': seconds or 0}
try:
self.assert_extension_exists(ext_name).execute_script(ext_name, args)
except UnknownMethodException:
# TODO: Remove the fallback
self.mark_extension_absence(ext_name).execute(Command.LOCK, args)
self.execute_script(ext_name, args)
return self

def unlock(self) -> Self:
Expand All @@ -53,13 +45,9 @@ def unlock(self) -> Self:
Union['WebDriver', 'HardwareActions']: Self instance
"""
ext_name = 'mobile: unlock'
try:
if not self.assert_extension_exists(ext_name).execute_script('mobile: isLocked'):
return self
self.execute_script(ext_name)
except UnknownMethodException:
# TODO: Remove the fallback
self.mark_extension_absence(ext_name).execute(Command.UNLOCK)
if not self.execute_script('mobile: isLocked'):
return self
self.execute_script(ext_name)
return self

def is_locked(self) -> bool:
Expand All @@ -69,11 +57,7 @@ def is_locked(self) -> bool:
`True` if the device is locked
"""
ext_name = 'mobile: isLocked'
try:
return self.assert_extension_exists(ext_name).execute_script('mobile: isLocked')
except UnknownMethodException:
# TODO: Remove the fallback
return self.mark_extension_absence(ext_name).execute(Command.IS_LOCKED)['value']
return self.execute_script(ext_name)

def shake(self) -> Self:
"""Shake the device.
Expand All @@ -82,11 +66,7 @@ def shake(self) -> Self:
Union['WebDriver', 'HardwareActions']: Self instance
"""
ext_name = 'mobile: shake'
try:
self.assert_extension_exists(ext_name).execute_script(ext_name)
except UnknownMethodException:
# TODO: Remove the fallback
self.mark_extension_absence(ext_name).execute(Command.SHAKE)
self.execute_script(ext_name)
return self

def touch_id(self, match: bool) -> Self:
Expand Down Expand Up @@ -125,25 +105,8 @@ def finger_print(self, finger_id: int) -> Self:
"""
ext_name = 'mobile: fingerprint'
args = {'fingerprintId': finger_id}
try:
self.assert_extension_exists(ext_name).execute_script(ext_name, args)
except UnknownMethodException:
self.mark_extension_absence(ext_name).execute(Command.FINGER_PRINT, args)
self.execute_script(ext_name, args)
return self

def _add_commands(self) -> None:
self.command_executor.add_command(Command.LOCK, 'POST', '/session/$sessionId/appium/device/lock')
self.command_executor.add_command(Command.UNLOCK, 'POST', '/session/$sessionId/appium/device/unlock')
self.command_executor.add_command(Command.IS_LOCKED, 'POST', '/session/$sessionId/appium/device/is_locked')
self.command_executor.add_command(Command.SHAKE, 'POST', '/session/$sessionId/appium/device/shake')
self.command_executor.add_command(Command.TOUCH_ID, 'POST', '/session/$sessionId/appium/simulator/touch_id')
self.command_executor.add_command(
Command.TOGGLE_TOUCH_ID_ENROLLMENT,
'POST',
'/session/$sessionId/appium/simulator/toggle_touch_id_enrollment',
)
self.command_executor.add_command(
Command.FINGER_PRINT,
'POST',
'/session/$sessionId/appium/device/finger_print',
)
pass
8 changes: 2 additions & 6 deletions test/unit/webdriver/device/fingerprint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ class TestWebDriverFingerprint:
@httpretty.activate
def test_finger_print(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/finger_print'),
# body is None
)
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/execute/sync'),
Expand All @@ -36,4 +31,5 @@ def test_finger_print(self):
assert isinstance(driver.finger_print(1), WebDriver)

d = get_httpretty_request_body(httpretty.last_request())
assert d.get('fingerprintId', d['args'][0]['fingerprintId']) == 1
assert d['script'] == 'mobile: fingerprint'
assert d['args'][0]['fingerprintId'] == 1
36 changes: 14 additions & 22 deletions test/unit/webdriver/device/lock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,28 @@ class TestWebDriverLockAndroid:
@httpretty.activate
def test_lock(self):
driver = android_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}')
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
driver.lock(1)

d = get_httpretty_request_body(httpretty.last_request())
assert d.get('seconds', d['args'][0]['seconds']) == 1
assert d['script'] == 'mobile: lock'
assert d['args'][0]['seconds'] == 1

@httpretty.activate
def test_lock_no_args(self):
driver = android_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}')
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
driver.lock()

@httpretty.activate
def test_islocked_false(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": false}'
)
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": false}')
assert driver.is_locked() is False

@httpretty.activate
def test_islocked_true(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": true}'
)
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}')
assert driver.is_locked() is True

Expand All @@ -59,45 +52,41 @@ def test_unlock(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/unlock'),
appium_command('/session/1234567890/execute/sync'),
responses=[
httpretty.Response(body='{"value": true}'),
httpretty.Response(body='{"value": ""}'),
],
)
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.unlock(), WebDriver)


class TestWebDriverLockIOS:
@httpretty.activate
def test_lock(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}')
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
driver.lock(1)

d = get_httpretty_request_body(httpretty.last_request())
assert d.get('seconds', d['args'][0]['seconds']) == 1
assert d['script'] == 'mobile: lock'
assert d['args'][0]['seconds'] == 1

@httpretty.activate
def test_lock_no_args(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}')
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
driver.lock()

@httpretty.activate
def test_islocked_false(self):
driver = ios_w3c_driver()
httpretty.register_uri(
httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": false}'
)
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": false}')
assert driver.is_locked() is False

@httpretty.activate
def test_islocked_true(self):
driver = ios_w3c_driver()
httpretty.register_uri(
httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": true}'
)
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}')
assert driver.is_locked() is True

Expand All @@ -106,9 +95,12 @@ def test_unlock(self):
driver = ios_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/unlock'),
appium_command('/session/1234567890/execute/sync'),
responses=[
httpretty.Response(body='{"value": true}'),
httpretty.Response(body='{"value": ""}'),
],
)
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.unlock(), WebDriver)

@httpretty.activate
Expand Down
4 changes: 0 additions & 4 deletions test/unit/webdriver/device/shake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ class TestWebDriverShake:
@httpretty.activate
def test_shake(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/shake'),
)
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/execute/sync'),
Expand Down
Loading