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
12 changes: 6 additions & 6 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ indent-width = 4

[lint]
select = [
# Pyflakes
"F",
# Pylint
"PL",
# isort
"I",
"F", # Pyflakes
"PL", # Pylint
"I", # isort
"PERF", # perflint
"FURB", # Refurb
"SIM" # Simplify
]

[lint.per-file-ignores]
Expand Down
6 changes: 3 additions & 3 deletions appium/webdriver/appium_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def start(self, **kwargs: Any) -> sp.Popen:
"""
self.stop()

env = kwargs['env'] if 'env' in kwargs else None
env = kwargs.get('env')
node: str = kwargs.get('node') or get_node()
npm: str = kwargs.get('npm') or get_npm()
main_script: str = kwargs.get('main_script') or get_main_script(node, npm)
# A workaround for https://github.com/appium/python-client/issues/534
default_std = sp.DEVNULL if sys.platform == 'win32' else sp.PIPE
stdout = kwargs['stdout'] if 'stdout' in kwargs else default_std
stderr = kwargs['stderr'] if 'stderr' in kwargs else default_std
stdout = kwargs.get('stdout', default_std)
stderr = kwargs.get('stderr', default_std)
timeout_ms = int(kwargs['timeout_ms']) if 'timeout_ms' in kwargs else STARTUP_TIMEOUT_MS
args: List[str] = [node, main_script]
if 'args' in kwargs:
Expand Down
4 changes: 1 addition & 3 deletions appium/webdriver/extensions/action_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
actions.w3c_actions.pointer_action.release()
actions.perform()
else:
finger = 0
actions = ActionChains(cast('WebDriver', self))
actions.w3c_actions.devices = []

for position in positions:
finger += 1
for finger, position in enumerate(positions, start=1):
x = position[0]
y = position[1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ def inject_mock_image(self, value: str) -> str:
Returns:
str: Image ID of the injected image.
"""
if os.path.isfile(value):
base64_encoded_image = encode_file_to_base64(value)
else:
base64_encoded_image = value
base64_encoded_image = encode_file_to_base64(value) if os.path.isfile(value) else value
return self.execute_flutter_command('injectImage', {'base64Image': base64_encoded_image})

def activate_injected_image(self, image_id: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ dev = [
"httpretty~=1.1",
"mock~=5.2",
"mypy>=1.17,<3.0",
"pre-commit~=4.2",
"pre-commit~=4.6",
"pytest>=8.4,<10.0",
"pytest-cov>=6.2,<8.0",
"pytest-xdist~=3.8",
"python-dateutil~=2.9",
"ruff~=0.15",
"ruff~=0.16",
"types-python-dateutil~=2.9",

# for release
Expand Down
5 changes: 1 addition & 4 deletions test/functional/flutter_integration/helper/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ def device_name() -> str:
Get a unique device name for the current worker.
Uses the base device name and appends the port number for uniqueness.
"""
if is_platform_android():
prefix = 'Android Emulator'
else:
prefix = os.environ['IPHONE_MODEL']
prefix = 'Android Emulator' if is_platform_android() else os.environ['IPHONE_MODEL']

worker_info = get_worker_info()

Expand Down
4 changes: 2 additions & 2 deletions test/functional/ios/safari_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def driver() -> Generator['WebDriver', None, None]:
def test_context(driver: 'WebDriver') -> None:
"""Test Safari context switching."""
contexts = driver.contexts
assert 'NATIVE_APP' == contexts[0]
assert contexts[0] == 'NATIVE_APP'
assert contexts[1].startswith('WEBVIEW_')
driver.switch_to.context(contexts[1])
assert 'WEBVIEW_' in driver.current_context
Expand All @@ -73,7 +73,7 @@ def test_navigation(driver: 'WebDriver') -> None:
driver.get('http://google.com')
for _ in range(5):
time.sleep(0.5)
if 'Google' == driver.title:
if driver.title == 'Google':
return

pytest.fail('The title was wrong')
45 changes: 23 additions & 22 deletions test/unit/webdriver/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_install_app(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
result = driver.install_app('path/to/app')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'app': 'path/to/app', 'appPath': 'path/to/app'}],
'script': 'mobile: installApp',
} == get_httpretty_request_body(httpretty.last_request())
}
assert isinstance(result, WebDriver)


Expand All @@ -40,10 +40,10 @@ def test_remove_app(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
result = driver.remove_app('com.app.id')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'appId': 'com.app.id', 'bundleId': 'com.app.id'}],
'script': 'mobile: removeApp',
} == get_httpretty_request_body(httpretty.last_request())
}
assert isinstance(result, WebDriver)


Expand All @@ -54,10 +54,10 @@ def test_app_installed(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}')
result = driver.is_app_installed('com.app.id')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'appId': 'com.app.id', 'bundleId': 'com.app.id'}],
'script': 'mobile: isAppInstalled',
} == get_httpretty_request_body(httpretty.last_request())
}
assert result is True


Expand All @@ -68,10 +68,10 @@ def test_terminate_app(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}')
result = driver.terminate_app('com.app.id')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'appId': 'com.app.id', 'bundleId': 'com.app.id'}],
'script': 'mobile: terminateApp',
} == get_httpretty_request_body(httpretty.last_request())
}
assert result is True


Expand All @@ -82,10 +82,10 @@ def test_activate_app(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
result = driver.activate_app('com.app.id')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'appId': 'com.app.id', 'bundleId': 'com.app.id'}],
'script': 'mobile: activateApp',
} == get_httpretty_request_body(httpretty.last_request())
}
assert isinstance(result, WebDriver)


Expand All @@ -96,7 +96,7 @@ def test_background_app(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}')
result = driver.background_app(0)

assert {'args': [{'seconds': 0}], 'script': 'mobile: backgroundApp'} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'args': [{'seconds': 0}], 'script': 'mobile: backgroundApp'}
assert isinstance(result, WebDriver)


Expand All @@ -107,10 +107,10 @@ def test_query_app_state(driver_func):
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": 3}')
result = driver.query_app_state('com.app.id')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'appId': 'com.app.id', 'bundleId': 'com.app.id'}],
'script': 'mobile: queryAppState',
} == get_httpretty_request_body(httpretty.last_request())
}
assert result is ApplicationState.RUNNING_IN_BACKGROUND


Expand All @@ -125,8 +125,8 @@ def test_app_strings(driver_func):
)
result = driver.app_strings()

assert {'args': [{}], 'script': 'mobile: getAppStrings'} == get_httpretty_request_body(httpretty.last_request())
assert "You can't wipe my data, you are a monkey!" == result['monkey_wipe_data'], result
assert get_httpretty_request_body(httpretty.last_request()) == {'args': [{}], 'script': 'mobile: getAppStrings'}
assert result['monkey_wipe_data'] == "You can't wipe my data, you are a monkey!", result


@pytest.mark.parametrize('driver_func', [android_w3c_driver, ios_w3c_driver])
Expand All @@ -140,10 +140,11 @@ def test_app_strings_with_lang(driver_func):
)
result = driver.app_strings('en')

assert {'args': [{'language': 'en'}], 'script': 'mobile: getAppStrings'} == get_httpretty_request_body(
httpretty.last_request()
)
assert "You can't wipe my data, you are a monkey!" == result['monkey_wipe_data'], result
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'language': 'en'}],
'script': 'mobile: getAppStrings',
}
assert result['monkey_wipe_data'] == "You can't wipe my data, you are a monkey!", result


@pytest.mark.parametrize('driver_func', [android_w3c_driver, ios_w3c_driver])
Expand All @@ -157,8 +158,8 @@ def test_app_strings_with_lang_and_file(driver_func):
)
result = driver.app_strings('en', 'some_file')

assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'language': 'en', 'stringFile': 'some_file'}],
'script': 'mobile: getAppStrings',
} == get_httpretty_request_body(httpretty.last_request())
assert "You can't wipe my data, you are a monkey!" == result['monkey_wipe_data'], result
}
assert result['monkey_wipe_data'] == "You can't wipe my data, you are a monkey!", result
6 changes: 3 additions & 3 deletions test/unit/webdriver/context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_get_contexts(self):
httpretty.GET, appium_command('/session/1234567890/contexts'), body='{"value": ["NATIVE_APP", "CHROMIUM"]}'
)

assert ['NATIVE_APP', 'CHROMIUM'] == driver.contexts
assert driver.contexts == ['NATIVE_APP', 'CHROMIUM']

@httpretty.activate
def test_switch_to_context(self):
Expand All @@ -40,7 +40,7 @@ def test_switch_to_context(self):

driver.switch_to.context(None)

assert {'name': None} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'name': None}

@httpretty.activate
def test_switch_to_context_native_app(self):
Expand All @@ -49,4 +49,4 @@ def test_switch_to_context_native_app(self):

driver.switch_to.context('NATIVE_APP')

assert {'name': 'NATIVE_APP'} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'name': 'NATIVE_APP'}
4 changes: 2 additions & 2 deletions test/unit/webdriver/device/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_open_notifications(self):
driver = android_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.open_notifications(), WebDriver)
assert {'args': [], 'script': 'mobile: openNotifications'} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'args': [], 'script': 'mobile: openNotifications'}

@httpretty.activate
def test_current_package(self):
Expand All @@ -35,4 +35,4 @@ def test_current_package(self):
body='{"value": ".ExamplePackage"}',
)
assert driver.current_package == '.ExamplePackage'
assert {'args': [], 'script': 'mobile: getCurrentPackage'} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'args': [], 'script': 'mobile: getCurrentPackage'}
25 changes: 14 additions & 11 deletions test/unit/webdriver/device/keyboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,42 @@ def test_hide_keyboard(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.hide_keyboard(), WebDriver)
assert {'args': [{}], 'script': 'mobile: hideKeyboard'} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'args': [{}], 'script': 'mobile: hideKeyboard'}

@httpretty.activate
def test_hide_keyboard_with_key(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.hide_keyboard(key_name='Done'), WebDriver)
assert {'args': [{'keys': ['Done']}], 'script': 'mobile: hideKeyboard'} == get_httpretty_request_body(
httpretty.last_request()
)
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'keys': ['Done']}],
'script': 'mobile: hideKeyboard',
}

@httpretty.activate
def test_hide_keyboard_with_key_and_strategy(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.hide_keyboard(strategy='pressKey', key='Done'), WebDriver)
# only 'keys' works
assert {'args': [{'keys': ['Done']}], 'script': 'mobile: hideKeyboard'} == get_httpretty_request_body(
httpretty.last_request()
)
assert get_httpretty_request_body(httpretty.last_request()) == {
'args': [{'keys': ['Done']}],
'script': 'mobile: hideKeyboard',
}

@httpretty.activate
def test_is_keyboard_shown(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
driver.is_keyboard_shown(), WebDriver
assert {'script': 'mobile: isKeyboardShown', 'args': []} == get_httpretty_request_body(httpretty.last_request())
assert get_httpretty_request_body(httpretty.last_request()) == {'script': 'mobile: isKeyboardShown', 'args': []}

@httpretty.activate
def test_press_button(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
driver.press_button('Home')
assert {'script': 'mobile: pressButton', 'args': [{'name': 'Home'}]} == get_httpretty_request_body(
httpretty.last_request()
)
assert get_httpretty_request_body(httpretty.last_request()) == {
'script': 'mobile: pressButton',
'args': [{'name': 'Home'}],
}
11 changes: 6 additions & 5 deletions test/unit/webdriver/device/lock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ def test_touch_id(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.touch_id(True), WebDriver)
assert {
assert get_httpretty_request_body(httpretty.last_request()) == {
'script': 'mobile: sendBiometricMatch',
'args': [{'match': True, 'type': 'touchId'}],
} == get_httpretty_request_body(httpretty.last_request())
}

@httpretty.activate
def test_enroll_biometric(self):
driver = ios_w3c_driver()
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'))
assert isinstance(driver.toggle_touch_id_enrollment(), WebDriver)
assert {'script': 'mobile: enrollBiometric', 'args': [{'isEnabled': True}]} == get_httpretty_request_body(
httpretty.last_request()
)
assert get_httpretty_request_body(httpretty.last_request()) == {
'script': 'mobile: enrollBiometric',
'args': [{'isEnabled': True}],
}
2 changes: 1 addition & 1 deletion test/unit/webdriver/log_events_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_get_events(self):
assert events['appium:funEvent'] == [12347]

d = get_httpretty_request_body(httpretty.last_request())
assert 'type' not in d.keys()
assert 'type' not in d

@httpretty.activate
def test_get_events_args(self):
Expand Down
2 changes: 1 addition & 1 deletion test/unit/webdriver/log_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def test_get_log():
assert log_types == ['logs as array']

d = get_httpretty_request_body(httpretty.last_request())
assert {'type': 'syslog'} == d
assert d == {'type': 'syslog'}
8 changes: 4 additions & 4 deletions test/unit/webdriver/screen_record_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_start_recording_screen(self):
d = get_httpretty_request_body(httpretty.last_request())
assert d['options']['user'] == 'userA'
assert d['options']['pass'] == '12345'
assert 'password' not in d['options'].keys()
assert 'password' not in d['options']

@httpretty.activate
def test_stop_recording_screen(self):
Expand All @@ -40,7 +40,7 @@ def test_stop_recording_screen(self):
d = get_httpretty_request_body(httpretty.last_request())
assert d['options']['user'] == 'userA'
assert d['options']['pass'] == '12345'
assert 'password' not in d['options'].keys()
assert 'password' not in d['options']


class TestWebDriverScreenRecordIOS:
Expand All @@ -56,7 +56,7 @@ def test_start_recording_screen(self):
d = get_httpretty_request_body(httpretty.last_request())
assert d['options']['user'] == 'userA'
assert d['options']['pass'] == '12345'
assert 'password' not in d['options'].keys()
assert 'password' not in d['options']

@httpretty.activate
def test_stop_recording_screen(self):
Expand All @@ -71,4 +71,4 @@ def test_stop_recording_screen(self):
d = get_httpretty_request_body(httpretty.last_request())
assert d['options']['user'] == 'userA'
assert d['options']['pass'] == '12345'
assert 'password' not in d['options'].keys()
assert 'password' not in d['options']
Loading
Loading