16
16
# under the License.
17
17
18
18
import os
19
+ import typing
19
20
from subprocess import PIPE
20
21
21
22
from selenium .webdriver .common import service
22
23
from selenium .webdriver .common import utils
23
24
24
- DEFAULT_EXECUTABLE_PATH = "/usr/bin/safaridriver"
25
-
26
25
27
26
class Service (service .Service ):
28
27
"""
@@ -31,10 +30,10 @@ class Service(service.Service):
31
30
32
31
def __init__ (
33
32
self ,
34
- executable_path : str = DEFAULT_EXECUTABLE_PATH ,
35
- port = 0 ,
36
- quiet = False ,
37
- service_args = None ,
33
+ executable_path : str = "/usr/bin/safaridriver" ,
34
+ port : int = 0 ,
35
+ quiet : bool = False ,
36
+ service_args : typing . Optional [ typing . List [ str ]] = None ,
38
37
):
39
38
"""
40
39
Creates a new instance of the Service
@@ -52,23 +51,20 @@ def __init__(
52
51
message = "SafariDriver was not found; are you running Safari 10 or later? You can download Safari at https://developer.apple.com/safari/download/."
53
52
raise Exception (message )
54
53
55
- if port == 0 :
56
- port = utils .free_port ()
57
-
54
+ port = port or utils .free_port ()
58
55
self .service_args = service_args or []
59
-
60
56
self .quiet = quiet
61
57
log = PIPE
62
58
if quiet :
63
59
log = open (os .devnull , "w" , encoding = "utf-8" )
64
60
super ().__init__ (executable_path , port , log )
65
61
66
- def command_line_args (self ):
67
- return ["-p" , "%s" % self .port ] + self .service_args
62
+ def command_line_args (self ) -> typing . List [ str ] :
63
+ return ["-p" , f" { self .port } " ] + self .service_args
68
64
69
65
@property
70
- def service_url (self ):
66
+ def service_url (self ) -> str :
71
67
"""
72
68
Gets the url of the SafariDriver Service
73
69
"""
74
- return "http://localhost:%d" % self .port
70
+ return f "http://localhost:{ self .port } "
0 commit comments