Skip to content

Commit 64a6553

Browse files
committed
extract
1 parent b06ed8e commit 64a6553

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

appium/webdriver/webdriver.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ def add_command(self) -> Tuple[str, str]:
175175
raise NotImplementedError()
176176

177177

178+
def _get_client_config_and_connection(
179+
command_executor: Union[str, AppiumConnection], client_config: Optional[AppiumClientConfig]
180+
) -> tuple[AppiumConnection, Optional[AppiumClientConfig]]:
181+
if not isinstance(command_executor):
182+
return (command_executor, client_config)
183+
184+
# command_executor is str
185+
if client_config is None:
186+
# Do not keep None to avoid warnings in Selenium
187+
# which can prevent with ClientConfig instance usage.
188+
client_config = AppiumClientConfig(remote_server_addr=command_executor)
189+
return (AppiumConnection(client_config=client_config), client_config)
190+
191+
178192
class WebDriver(
179193
webdriver.Remote,
180194
ActionHelpers,
@@ -211,13 +225,9 @@ def __init__(
211225
options: Union[AppiumOptions, List[AppiumOptions], None] = None,
212226
client_config: Optional[AppiumClientConfig] = None,
213227
):
214-
if isinstance(command_executor, str):
215-
# Do not keep None to avoid warnings in Selenium which can prevent with ClientConfig instance usage.
216-
if client_config is None:
217-
client_config = AppiumClientConfig(remote_server_addr=command_executor)
218-
# To prevent generating RemoteConnection in selenium
219-
command_executor = AppiumConnection(client_config=client_config)
220-
228+
command_executor, client_config = _get_client_config_and_connection(
229+
command_executor=command_executor, client_config=client_config
230+
)
221231
super().__init__(
222232
command_executor=command_executor,
223233
file_detector=file_detector,

test/unit/webdriver/webdriver_test.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from appium.options.android import UiAutomator2Options
2323
from appium.webdriver.appium_connection import AppiumConnection
2424
from appium.webdriver.client_config import AppiumClientConfig
25-
from appium.webdriver.webdriver import ExtensionBase, WebDriver
25+
from appium.webdriver.webdriver import ExtensionBase, WebDriver, _get_client_config_and_connection
2626
from test.helpers.constants import SERVER_URL_BASE
2727
from test.unit.helper.test_helper import (
2828
android_w3c_driver,
@@ -420,6 +420,16 @@ def test_extention_command_check(self):
420420
'script': 'mobile: startActivity',
421421
} == get_httpretty_request_body(httpretty.last_request())
422422

423+
def test_get_client_config_and_connection(self):
424+
command_executor, client_config = _get_client_config_and_connection(
425+
command_executor='http://127.0.0.1:4723', client_config=None
426+
)
427+
428+
assert isinstance(command_executor, AppiumConnection)
429+
assert command_executor._url == 'http://127.0.0.1:4723'
430+
assert isinstance(client_config, AppiumClientConfig)
431+
assert client_config.remote_server_addr == 'http://127.0.0.1:4723'
432+
423433

424434
class SubWebDriver(WebDriver):
425435
def __init__(self, command_executor, options=None):

0 commit comments

Comments
 (0)