@@ -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+
178192class 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 ,
0 commit comments