@@ -201,7 +201,7 @@ class WebDriver(BaseWebDriver):
201201
202202 def __init__ (
203203 self ,
204- command_executor : Union [str , RemoteConnection ] = "http://127.0.0.1:4444" ,
204+ command_executor : Union [str , RemoteConnection , Service ] = "http://127.0.0.1:4444" ,
205205 keep_alive : bool = True ,
206206 file_detector : Optional [FileDetector ] = None ,
207207 options : Optional [Union [BaseOptions , list [BaseOptions ]]] = None ,
@@ -214,9 +214,10 @@ def __init__(
214214
215215 Parameters:
216216 -----------
217- command_executor : str or remote_connection.RemoteConnection
218- - Either a string representing the URL of the remote server or a custom
219- remote_connection.RemoteConnection object. Defaults to 'http://127.0.0.1:4444/wd/hub'.
217+ command_executor : str or remote_connection.RemoteConnection or service.Service
218+ - Either a string representing the URL of the remote server, a Service (containing
219+ the URL of the remote server), or a custom remote_connection.RemoteConnection object.
220+ Defaults to 'http://127.0.0.1:4444/wd/hub'.
220221 keep_alive : bool (Deprecated)
221222 - Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive. Defaults to True.
222223 file_detector : object or None
@@ -243,10 +244,15 @@ def __init__(
243244 capabilities = options .to_capabilities ()
244245 _ignore_local_proxy = options ._ignore_local_proxy
245246 self .command_executor = command_executor
247+ if isinstance (self .command_executor , Service ):
248+ # Make sure the service doesn't drop before this drops.
249+ # We don't use it, so it shouldn't be defined in types.
250+ self ._service = self .command_executor # type: ignore[attr-defined]
251+ self .command_executor = self .command_executor .service_url
246252 if isinstance (self .command_executor , (str , bytes )):
247253 self .command_executor = get_remote_connection (
248254 capabilities ,
249- command_executor = command_executor ,
255+ command_executor = self . command_executor ,
250256 keep_alive = keep_alive ,
251257 ignore_local_proxy = _ignore_local_proxy ,
252258 client_config = client_config ,
@@ -279,14 +285,6 @@ def __init__(
279285 self ._input = None
280286 self ._devtools = None
281287
282- @classmethod
283- def from_service (cls , service : Service , * args , ** kwargs ) -> Self :
284- self = cls (service .service_url , * args , ** kwargs )
285- # Make sure the service doesn't drop before this drops.
286- # We don't use it, so it shouldn't be defined in types.
287- self ._service = service # type: ignore[attr-defined]
288- return self
289-
290288 def __repr__ (self ):
291289 return f'<{ type (self ).__module__ } .{ type (self ).__name__ } (session="{ self .session_id } ")>'
292290
0 commit comments