Skip to content

Commit 31144ff

Browse files
committed
[py]: Additional types and tidying safari service
1 parent 4d8fc6b commit 31144ff

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

py/selenium/webdriver/safari/service.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
# under the License.
1717

1818
import os
19+
import typing
1920
from subprocess import PIPE
2021

2122
from selenium.webdriver.common import service
2223
from selenium.webdriver.common import utils
2324

24-
DEFAULT_EXECUTABLE_PATH = "/usr/bin/safaridriver"
25-
2625

2726
class Service(service.Service):
2827
"""
@@ -31,10 +30,10 @@ class Service(service.Service):
3130

3231
def __init__(
3332
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,
3837
):
3938
"""
4039
Creates a new instance of the Service
@@ -52,23 +51,20 @@ def __init__(
5251
message = "SafariDriver was not found; are you running Safari 10 or later? You can download Safari at https://developer.apple.com/safari/download/."
5352
raise Exception(message)
5453

55-
if port == 0:
56-
port = utils.free_port()
57-
54+
port = port or utils.free_port()
5855
self.service_args = service_args or []
59-
6056
self.quiet = quiet
6157
log = PIPE
6258
if quiet:
6359
log = open(os.devnull, "w", encoding="utf-8")
6460
super().__init__(executable_path, port, log)
6561

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
6864

6965
@property
70-
def service_url(self):
66+
def service_url(self) -> str:
7167
"""
7268
Gets the url of the SafariDriver Service
7369
"""
74-
return "http://localhost:%d" % self.port
70+
return f"http://localhost:{self.port}"

0 commit comments

Comments
 (0)