Appium-Python-Client 6.1.6__py3-none-any.whl → 6.1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import json
16
- from collections.abc import Sequence
16
+ from http import HTTPStatus
17
17
  from typing import Any
18
18
 
19
19
  import selenium.common.exceptions as sel_exceptions
@@ -21,106 +21,70 @@ from selenium.webdriver.remote import errorhandler
21
21
 
22
22
  import appium.common.exceptions as appium_exceptions
23
23
 
24
- ERROR_TO_EXC_MAPPING: dict[str, type[sel_exceptions.WebDriverException]] = {
25
- 'element click intercepted': sel_exceptions.ElementClickInterceptedException,
26
- 'element not interactable': sel_exceptions.ElementNotInteractableException,
27
- 'insecure certificate': sel_exceptions.InsecureCertificateException,
28
- 'invalid argument': sel_exceptions.InvalidArgumentException,
29
- 'invalid cookie domain': sel_exceptions.InvalidCookieDomainException,
30
- 'invalid element state': sel_exceptions.InvalidElementStateException,
31
- 'invalid selector': sel_exceptions.InvalidSelectorException,
32
- 'invalid session id': sel_exceptions.InvalidSessionIdException,
33
- 'javascript error': sel_exceptions.JavascriptException,
34
- 'move target out of bounds': sel_exceptions.MoveTargetOutOfBoundsException,
35
- 'no such alert': sel_exceptions.NoAlertPresentException,
36
- 'no such cookie': sel_exceptions.NoSuchCookieException,
37
- 'no such element': sel_exceptions.NoSuchElementException,
38
- 'no such frame': sel_exceptions.NoSuchFrameException,
39
- 'no such window': sel_exceptions.NoSuchWindowException,
40
- 'no such shadow root': sel_exceptions.NoSuchShadowRootException,
41
- 'script timeout': sel_exceptions.TimeoutException,
42
- 'session not created': sel_exceptions.SessionNotCreatedException,
43
- 'stale element reference': sel_exceptions.StaleElementReferenceException,
44
- 'detached shadow root': sel_exceptions.NoSuchShadowRootException,
45
- 'timeout': sel_exceptions.TimeoutException,
46
- 'unable to set cookie': sel_exceptions.UnableToSetCookieException,
47
- 'unable to capture screen': sel_exceptions.ScreenshotException,
48
- 'unexpected alert open': sel_exceptions.UnexpectedAlertPresentException,
49
- 'unknown command': sel_exceptions.UnknownMethodException,
50
- 'unknown error': sel_exceptions.WebDriverException,
51
- 'unknown method': sel_exceptions.UnknownMethodException,
52
- 'unsupported operation': sel_exceptions.UnknownMethodException,
53
- 'element not visible': sel_exceptions.ElementNotVisibleException,
54
- 'element not selectable': sel_exceptions.ElementNotSelectableException,
55
- 'invalid coordinates': sel_exceptions.InvalidCoordinatesException,
56
- }
57
-
58
-
59
- def format_stacktrace(original: None | str | Sequence) -> list[str]:
60
- if not original:
61
- return []
62
- if isinstance(original, str):
63
- return original.split('\n')
64
-
65
- result: list[str] = []
66
- try:
67
- for frame in original:
68
- if not isinstance(frame, dict):
69
- continue
70
-
71
- line = frame.get('lineNumber', '')
72
- file = frame.get('fileName', '<anonymous>')
73
- if line:
74
- file = f'{file}:{line}'
75
- meth = frame.get('methodName', '<anonymous>')
76
- if 'className' in frame:
77
- meth = f'{frame["className"]}.{meth}'
78
- result.append(f' at {meth} ({file})')
79
- except TypeError:
80
- pass
81
- return result
82
-
83
24
 
84
25
  class MobileErrorHandler(errorhandler.ErrorHandler):
85
26
  def check_response(self, response: dict[str, Any]) -> None:
86
- """
87
- https://www.w3.org/TR/webdriver/#errors
88
- """
27
+ """Handle W3C and HTTP error responses, retaining Appium-specific exception mappings."""
89
28
  payload = response.get('value', '')
90
- if isinstance(payload, dict):
91
- payload_dict = payload
92
- else:
93
- try:
94
- payload_dict = json.loads(payload)
95
- except (json.JSONDecodeError, TypeError):
96
- return
97
- if not isinstance(payload_dict, dict):
98
- return
99
- value = payload_dict.get('value')
100
- if not isinstance(value, dict):
101
- return
102
- error = value.get('error')
103
- if not error:
29
+ payload_dict = _parse_payload_dict(payload)
30
+ w3c_error = _extract_w3c_error(payload_dict)
31
+ if w3c_error is None:
32
+ _raise_if_http_error(response, payload, payload_dict)
104
33
  return
105
34
 
106
- message = value.get('message', error)
107
- stacktrace = value.get('stacktrace', '')
108
- # In theory, we should also be checking HTTP status codes.
109
- # Java client, for example, prints a warning if the actual `error`
110
- # value does not match to the response's HTTP status code.
111
- exception_class: type[sel_exceptions.WebDriverException] = ERROR_TO_EXC_MAPPING.get(
112
- error, sel_exceptions.WebDriverException
113
- )
114
- if exception_class is sel_exceptions.WebDriverException and message:
115
- if message == 'No such context found.':
35
+ error, value = w3c_error
36
+ # Pass the W3C error string as Selenium's internal status, never a
37
+ # JSONWP numeric status. Selenium handles data.text and stacktrace.
38
+ try:
39
+ super().check_response({'status': error, 'value': value})
40
+ except sel_exceptions.WebDriverException as exc:
41
+ if type(exc) is not sel_exceptions.WebDriverException:
42
+ raise
43
+ exception_class: type[sel_exceptions.WebDriverException]
44
+ if error in ('unknown command', 'unknown method', 'unsupported operation'):
45
+ exception_class = sel_exceptions.UnknownMethodException
46
+ elif exc.msg == 'No such context found.':
116
47
  exception_class = appium_exceptions.NoSuchContextException
117
- elif message == 'That command could not be executed in the current context.':
48
+ elif exc.msg == 'That command could not be executed in the current context.':
118
49
  exception_class = appium_exceptions.InvalidSwitchToTargetException
50
+ else:
51
+ raise
52
+ raise exception_class(msg=exc.msg, screen=exc.screen, stacktrace=exc.stacktrace) from exc
53
+
54
+
55
+ def _parse_payload_dict(payload: Any) -> dict[str, Any] | None:
56
+ if isinstance(payload, dict):
57
+ return payload
58
+ if isinstance(payload, str):
59
+ try:
60
+ loaded = json.loads(payload)
61
+ except ValueError:
62
+ return None
63
+ return loaded if isinstance(loaded, dict) else None
64
+ return None
65
+
66
+
67
+ def _extract_w3c_error(payload_dict: dict[str, Any] | None) -> tuple[str, dict[str, Any]] | None:
68
+ if payload_dict is None:
69
+ return None
70
+ value = payload_dict.get('value')
71
+ if not isinstance(value, dict):
72
+ return None
73
+ error = value.get('error')
74
+ if not isinstance(error, str) or not error:
75
+ return None
76
+ return error, value
77
+
119
78
 
120
- if exception_class is sel_exceptions.UnexpectedAlertPresentException:
121
- raise sel_exceptions.UnexpectedAlertPresentException(
122
- msg=message,
123
- stacktrace=format_stacktrace(stacktrace),
124
- alert_text=value.get('data'),
125
- )
126
- raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace))
79
+ def _raise_if_http_error(response: dict[str, Any], payload: Any, payload_dict: dict[str, Any] | None) -> None:
80
+ status = response.get('status')
81
+ if not isinstance(status, int) or isinstance(status, bool) or status < HTTPStatus.BAD_REQUEST:
82
+ return
83
+ if payload_dict is None:
84
+ msg = payload if isinstance(payload, str) and payload else f'HTTP error status: {status}'
85
+ raise sel_exceptions.WebDriverException(msg=msg)
86
+ if 'status' in payload_dict:
87
+ return
88
+ value = payload_dict.get('value')
89
+ msg = value if isinstance(value, str) and value else json.dumps(payload_dict)
90
+ raise sel_exceptions.WebDriverException(msg=msg)
@@ -74,8 +74,9 @@ class Applications(CanExecuteCommands, CanExecuteScripts):
74
74
  Returns:
75
75
  Union['WebDriver', 'Applications']: Self instance
76
76
  """
77
+ ext_name = 'mobile: installApp'
77
78
  self.execute_script(
78
- 'mobile: installApp',
79
+ ext_name,
79
80
  {
80
81
  'app': app_path,
81
82
  'appPath': app_path,
@@ -216,7 +216,7 @@ def _get_remote_connection_and_client_config(
216
216
  def _get_direct_connect_value(caps: dict[str, Any], key: str) -> Any:
217
217
  for candidate in (f'{APPIUM_PREFIX}{key}', key):
218
218
  value = caps.get(candidate)
219
- if value is not None and value != '':
219
+ if value is not None and (value != '' or key == 'directConnectPath'):
220
220
  return value
221
221
  return None
222
222
 
@@ -281,7 +281,7 @@ class WebDriver(
281
281
 
282
282
  self.error_handler = MobileErrorHandler()
283
283
 
284
- effective_client_config = client_config or getattr(self.command_executor, 'client_config', None)
284
+ effective_client_config = self.command_executor.client_config
285
285
  if isinstance(effective_client_config, AppiumClientConfig) and effective_client_config.direct_connection:
286
286
  self._update_command_executor(keep_alive=effective_client_config.keep_alive)
287
287
 
@@ -339,7 +339,7 @@ class WebDriver(
339
339
 
340
340
  logger.debug('Updated request endpoint to %s', executor)
341
341
 
342
- # Override command executor.
342
+ # Keep the existing executor, including custom constructor arguments and state.
343
343
  # The client configuration given by a user, e.g. the read timeout, the proxy or
344
344
  # the authentication credentials, must be kept as-is. Only the endpoint the client
345
345
  # talks to changes, thus a copy of the current configuration is reused instead of
@@ -347,11 +347,13 @@ class WebDriver(
347
347
  client_config = copy.copy(self.command_executor.client_config)
348
348
  client_config.remote_server_addr = executor
349
349
  client_config.keep_alive = keep_alive
350
- if isinstance(self.command_executor, AppiumConnection):
351
- self.command_executor = type(self.command_executor)(client_config=client_config)
352
- else:
353
- self.command_executor = RemoteConnection(client_config=client_config)
354
- self._add_commands()
350
+ if hasattr(self.command_executor, '_conn'):
351
+ self.command_executor._conn.clear()
352
+ self.command_executor._client_config = client_config
353
+ # Proxy selection (including no_proxy) can change with the endpoint.
354
+ self.command_executor._proxy_url = client_config.get_proxy_url()
355
+ if keep_alive:
356
+ self.command_executor._conn = self.command_executor._get_connection_manager()
355
357
 
356
358
  # https://github.com/SeleniumHQ/selenium/blob/06fdf2966df6bca47c0ae45e8201cd30db9b9a49/py/selenium/webdriver/remote/webdriver.py#L277
357
359
  # noinspection PyAttributeOutsideInit
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: Appium-Python-Client
3
- Version: 6.1.6
3
+ Version: 6.1.8
4
4
  Summary: Python client for Appium
5
5
  Project-URL: Homepage, https://appium.io/
6
6
  Project-URL: Repository, https://github.com/appium/python-client
@@ -278,17 +278,17 @@ appium/webdriver/client_config.py,sha256=iuVcGsBF9eGNsF_gzs8b6vZWS0iI1u7actaBGBw
278
278
  appium/webdriver/clipboard_content_type.py,sha256=Tyks8xA2dqvuQGEV4iVYr-iMvB-hsQBEcu8wWBxtJ4M,661
279
279
  appium/webdriver/command_method.py,sha256=2IgtxQMSoUiS_3nAwM4rS0Rx0avBWlX2sq2k-K79zZs,792
280
280
  appium/webdriver/connectiontype.py,sha256=ZDiibECp-bdFkWy2_PRrJboi0bf-QQDWNsnpraScOkE,1567
281
- appium/webdriver/errorhandler.py,sha256=_aT6Qo64ARGch7evG2Uku4-l8wkDaM1R2o06PWXxwr8,5640
281
+ appium/webdriver/errorhandler.py,sha256=GD84AUrnby9Hrj_70rg5X_zBC5LGkwdJcY_oSdaNs00,3727
282
282
  appium/webdriver/locator_converter.py,sha256=uUdJsX1o0E8x-StcJvO5gFFJbcRzhOmySfgPqJ0UaU4,999
283
283
  appium/webdriver/mobilecommand.py,sha256=B_okscraJMPrN4hSyetSNddkOZ0PyTzsQvBdYHHQqvM,3162
284
284
  appium/webdriver/switch_to.py,sha256=px12JwzTXngGWJiOfKXKaIc_QOoB1144Dv2U19jebSo,1386
285
- appium/webdriver/webdriver.py,sha256=TOU7WYEyXSYJWwraIC4_L3-W79Paen9GGrWYYWtJrIA,19936
285
+ appium/webdriver/webdriver.py,sha256=nPjth2bMg6lhCEy4GvOkBoUfk-IOzRSghXp7peVTf7Y,20126
286
286
  appium/webdriver/webelement.py,sha256=P7ev_K9DwmMJ8oS6u4TpLi7R5xFcsSE8dmu2ICfrvJA,4472
287
287
  appium/webdriver/common/__init__.py,sha256=4MapoJ3p5LiP0AsHMgL2xoPTIFno4dcH1GSoxaZzv4w,623
288
288
  appium/webdriver/common/appiumby.py,sha256=cO3RpM41ht9kPzgLFvKwBLhVv832WjOsnuP0vEqvAeY,1896
289
289
  appium/webdriver/extensions/__init__.py,sha256=wSUl6yC2TJNla7xbHXkCfn9J1LpQs9UIx8oOs6V8kZA,567
290
290
  appium/webdriver/extensions/action_helpers.py,sha256=yK_SDJCl-PeepC3C-zXJnfCLkcFwRz3NB_SH4JicFTw,9388
291
- appium/webdriver/extensions/applications.py,sha256=KnRD9-JilgYtBuy8dik2iGI5GeS2RPQws2BSdKL9HDo,6575
291
+ appium/webdriver/extensions/applications.py,sha256=Y-ewfdtgQ4CIRX4x_h7NLnjcn_qGVeXm3QCpHhBpPm4,6603
292
292
  appium/webdriver/extensions/clipboard.py,sha256=G0qvK5I5DP87IR8A5ICMC-_mtEPktSCOPKif-RZwX2M,3470
293
293
  appium/webdriver/extensions/context.py,sha256=Ldhyld4n_JRu9YhgnIOtF-qZQYsXlYrjdYHStcIV2jA,1994
294
294
  appium/webdriver/extensions/device_time.py,sha256=CRponsom_3wAEFuxVa6_zUa7BoFkmGCSIeWzCrPTV1g,2009
@@ -319,7 +319,7 @@ appium/webdriver/extensions/flutter_integration/__init__.py,sha256=wSUl6yC2TJNla
319
319
  appium/webdriver/extensions/flutter_integration/flutter_commands.py,sha256=1bAczDwqr40Rrbln321cIVG83ghar7-27aerRAKbfMs,12306
320
320
  appium/webdriver/extensions/flutter_integration/flutter_finder.py,sha256=fq3ORd4-PGUurJn0xLUMfqg7P9sE-Syv353brgcyGfM,2039
321
321
  appium/webdriver/extensions/flutter_integration/scroll_directions.py,sha256=y1BCEbWHJ86ivj5quhln10uwV9fWsA6nsdQ18j1Ua3E,123
322
- appium_python_client-6.1.6.dist-info/METADATA,sha256=C3lWw-UC-gCA02DZjO60AgEb-4vyeQIuoU2DSDhT_rU,22201
323
- appium_python_client-6.1.6.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
324
- appium_python_client-6.1.6.dist-info/licenses/LICENSE,sha256=QxeKfXNmPWCfFyrXiwdVzMFPFMK0nlBrKhYLUoIcqhk,11384
325
- appium_python_client-6.1.6.dist-info/RECORD,,
322
+ appium_python_client-6.1.8.dist-info/METADATA,sha256=uFI1yDf9gB1TKsd49m6IHcSYeP4ScGWhowsdaWOxM3w,22201
323
+ appium_python_client-6.1.8.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
324
+ appium_python_client-6.1.8.dist-info/licenses/LICENSE,sha256=QxeKfXNmPWCfFyrXiwdVzMFPFMK0nlBrKhYLUoIcqhk,11384
325
+ appium_python_client-6.1.8.dist-info/RECORD,,