|
22 | 22 | WebDriverException, |
23 | 23 | ) |
24 | 24 | from selenium.webdriver.common.by import By |
| 25 | +from selenium.webdriver.remote.client_config import ClientConfig |
25 | 26 | from selenium.webdriver.remote.command import Command as RemoteCommand |
26 | 27 | from selenium.webdriver.remote.remote_connection import RemoteConnection |
27 | 28 | from typing_extensions import Self |
|
62 | 63 | from .webelement import WebElement as MobileWebElement |
63 | 64 |
|
64 | 65 |
|
| 66 | +class AppiumLocatorConverter: |
| 67 | + def convert(self, by, value): |
| 68 | + return (by, value) |
| 69 | + |
| 70 | + |
65 | 71 | class ExtensionBase: |
66 | 72 | """ |
67 | 73 | Used to define an extension command as driver's methods. |
@@ -200,32 +206,28 @@ class WebDriver( |
200 | 206 | Sms, |
201 | 207 | SystemBars, |
202 | 208 | ): |
203 | | - def __init__( |
| 209 | + def __init__( # noqa: PLR0913 |
204 | 210 | self, |
205 | 211 | command_executor: Union[str, AppiumConnection] = 'http://127.0.0.1:4444/wd/hub', |
206 | 212 | keep_alive: bool = True, |
207 | 213 | direct_connection: bool = True, |
208 | 214 | extensions: Optional[List['WebDriver']] = None, |
209 | 215 | strict_ssl: bool = True, |
210 | 216 | options: Union[AppiumOptions, List[AppiumOptions], None] = None, |
| 217 | + client_config: Optional[ClientConfig] = None, |
211 | 218 | ): |
212 | | - if strict_ssl is False: |
213 | | - # noinspection PyPackageRequirements |
214 | | - import urllib3 |
215 | | - |
216 | | - # noinspection PyPackageRequirements |
217 | | - import urllib3.exceptions |
218 | | - |
219 | | - # noinspection PyUnresolvedReferences |
220 | | - AppiumConnection.set_certificate_bundle_path(None) |
221 | | - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
222 | | - |
223 | 219 | if isinstance(command_executor, str): |
224 | 220 | command_executor = AppiumConnection(command_executor, keep_alive=keep_alive) |
225 | 221 |
|
| 222 | + if client_config is None: |
| 223 | + client_config = ClientConfig(remote_server_addr=command_executor, ignore_certificates=not strict_ssl) |
| 224 | + |
226 | 225 | super().__init__( |
227 | 226 | command_executor=command_executor, |
228 | 227 | options=options, |
| 228 | + locator_converter=AppiumLocatorConverter(), |
| 229 | + web_element_cls=MobileWebElement, |
| 230 | + client_config=client_config, |
229 | 231 | ) |
230 | 232 |
|
231 | 233 | if hasattr(self, 'command_executor'): |
@@ -346,72 +348,6 @@ def get_status(self) -> Dict: |
346 | 348 | """ |
347 | 349 | return self.execute(Command.GET_STATUS)['value'] |
348 | 350 |
|
349 | | - def find_element(self, by: str = AppiumBy.ID, value: Union[str, Dict, None] = None) -> MobileWebElement: |
350 | | - """ |
351 | | - Find an element given a AppiumBy strategy and locator |
352 | | -
|
353 | | - Args: |
354 | | - by: The strategy |
355 | | - value: The locator |
356 | | -
|
357 | | - Usage: |
358 | | - driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='accessibility_id') |
359 | | -
|
360 | | - Returns: |
361 | | - `appium.webdriver.webelement.WebElement`: The found element |
362 | | -
|
363 | | - """ |
364 | | - # We prefer to patch locators in the client code |
365 | | - # Checking current context every time a locator is accessed could significantly slow down tests |
366 | | - # Check https://github.com/appium/python-client/pull/724 before submitting any issue |
367 | | - # if by == By.ID: |
368 | | - # by = By.CSS_SELECTOR |
369 | | - # value = '[id="%s"]' % value |
370 | | - # elif by == By.TAG_NAME: |
371 | | - # by = By.CSS_SELECTOR |
372 | | - # elif by == By.CLASS_NAME: |
373 | | - # by = By.CSS_SELECTOR |
374 | | - # value = ".%s" % value |
375 | | - # elif by == By.NAME: |
376 | | - # by = By.CSS_SELECTOR |
377 | | - # value = '[name="%s"]' % value |
378 | | - |
379 | | - return self.execute(RemoteCommand.FIND_ELEMENT, {'using': by, 'value': value})['value'] |
380 | | - |
381 | | - def find_elements(self, by: str = AppiumBy.ID, value: Union[str, Dict, None] = None) -> Union[List[MobileWebElement], List]: |
382 | | - """ |
383 | | - Find elements given a AppiumBy strategy and locator |
384 | | -
|
385 | | - Args: |
386 | | - by: The strategy |
387 | | - value: The locator |
388 | | -
|
389 | | - Usage: |
390 | | - driver.find_elements(by=AppiumBy.ACCESSIBILITY_ID, value='accessibility_id') |
391 | | -
|
392 | | - Returns: |
393 | | - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements |
394 | | - """ |
395 | | - # We prefer to patch locators in the client code |
396 | | - # Checking current context every time a locator is accessed could significantly slow down tests |
397 | | - # Check https://github.com/appium/python-client/pull/724 before submitting any issue |
398 | | - # if by == By.ID: |
399 | | - # by = By.CSS_SELECTOR |
400 | | - # value = '[id="%s"]' % value |
401 | | - # elif by == By.TAG_NAME: |
402 | | - # by = By.CSS_SELECTOR |
403 | | - # elif by == By.CLASS_NAME: |
404 | | - # by = By.CSS_SELECTOR |
405 | | - # value = ".%s" % value |
406 | | - # elif by == By.NAME: |
407 | | - # by = By.CSS_SELECTOR |
408 | | - # value = '[name="%s"]' % value |
409 | | - |
410 | | - # Return empty list if driver returns null |
411 | | - # See https://github.com/SeleniumHQ/selenium/issues/4555 |
412 | | - |
413 | | - return self.execute(RemoteCommand.FIND_ELEMENTS, {'using': by, 'value': value})['value'] or [] |
414 | | - |
415 | 351 | def create_web_element(self, element_id: Union[int, str]) -> MobileWebElement: |
416 | 352 | """Creates a web element with the specified element_id. |
417 | 353 |
|
|
0 commit comments