diff --git a/py/selenium/webdriver/safari/options.py b/py/selenium/webdriver/safari/options.py index cc8436ce5b077..bed8bf8c8558e 100644 --- a/py/selenium/webdriver/safari/options.py +++ b/py/selenium/webdriver/safari/options.py @@ -34,10 +34,10 @@ class Options(ArgOptions): KEY = "safari.options" # @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari - AUTOMATIC_INSPECTION = 'safari:automaticInspection' - AUTOMATIC_PROFILING = 'safari:automaticProfiling' + AUTOMATIC_INSPECTION = "safari:automaticInspection" + AUTOMATIC_PROFILING = "safari:automaticProfiling" - SAFARI_TECH_PREVIEW = 'Safari Technology Preview' + SAFARI_TECH_PREVIEW = "Safari Technology Preview" def __init__(self) -> None: super().__init__() @@ -63,8 +63,7 @@ def binary_location(self, value: str) -> None: self._binary_location = value def to_capabilities(self) -> dict: - """Marshals the options to an desired capabilities object. - """ + """Marshals the options to an desired capabilities object.""" # This intentionally looks at the internal properties # so if a binary or profile has _not_ been set, # it will defer to geckodriver to find the system Firefox @@ -89,7 +88,7 @@ def default_capabilities(self) -> typing.Dict[str, str]: @property def automatic_inspection(self) -> bool: - """:Returns: The option Automatic Inspection value """ + """:Returns: The option Automatic Inspection value""" return self._caps.get(self.AUTOMATIC_INSPECTION) @automatic_inspection.setter @@ -105,7 +104,7 @@ def automatic_inspection(self, value: bool) -> None: @property def automatic_profiling(self) -> bool: - """:Returns: The options Automatic Profiling value """ + """:Returns: The options Automatic Profiling value""" return self._caps.get(self.AUTOMATIC_PROFILING) @automatic_profiling.setter @@ -122,7 +121,7 @@ def automatic_profiling(self, value: bool) -> None: @property def use_technology_preview(self) -> bool: """:Returns: whether BROWSER_NAME is equal to Safari Technology Preview""" - return self._caps.get('browserName') == self.SAFARI_TECH_PREVIEW + return self._caps.get("browserName") == self.SAFARI_TECH_PREVIEW @use_technology_preview.setter def use_technology_preview(self, value: bool) -> None: @@ -133,4 +132,4 @@ def use_technology_preview(self, value: bool) -> None: - value: boolean value """ - self.set_capability('browserName', self.SAFARI_TECH_PREVIEW if value else 'safari') + self.set_capability("browserName", self.SAFARI_TECH_PREVIEW if value else "safari") diff --git a/py/selenium/webdriver/safari/remote_connection.py b/py/selenium/webdriver/safari/remote_connection.py index cd2139b4a941a..5a654769f5da8 100644 --- a/py/selenium/webdriver/safari/remote_connection.py +++ b/py/selenium/webdriver/safari/remote_connection.py @@ -21,10 +21,10 @@ class SafariRemoteConnection(RemoteConnection): - browser_name = DesiredCapabilities.SAFARI['browserName'] + browser_name = DesiredCapabilities.SAFARI["browserName"] def __init__(self, remote_server_addr, keep_alive=True, ignore_proxy=False): super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy) - self._commands["GET_PERMISSIONS"] = ('GET', '/session/$sessionId/apple/permissions') - self._commands["SET_PERMISSIONS"] = ('POST', '/session/$sessionId/apple/permissions') - self._commands["ATTACH_DEBUGGER"] = ('POST', '/session/$sessionId/apple/attach_debugger') + self._commands["GET_PERMISSIONS"] = ("GET", "/session/$sessionId/apple/permissions") + self._commands["SET_PERMISSIONS"] = ("POST", "/session/$sessionId/apple/permissions") + self._commands["ATTACH_DEBUGGER"] = ("POST", "/session/$sessionId/apple/attach_debugger") diff --git a/py/selenium/webdriver/safari/service.py b/py/selenium/webdriver/safari/service.py index e24e1c5cd15d0..fb15135f61bd6 100644 --- a/py/selenium/webdriver/safari/service.py +++ b/py/selenium/webdriver/safari/service.py @@ -29,8 +29,13 @@ class Service(service.Service): Object that manages the starting and stopping of the SafariDriver """ - def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH, - port=0, quiet=False, service_args=None): + def __init__( + self, + executable_path: str = DEFAULT_EXECUTABLE_PATH, + port=0, + quiet=False, + service_args=None, + ): """ Creates a new instance of the Service @@ -38,7 +43,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH, - executable_path : Path to the SafariDriver - port : Port the service is running on - quiet : Suppress driver stdout and stderr - - service_args : List of args to pass to the safaridriver service """ + - service_args : List of args to pass to the safaridriver service""" if not os.path.exists(executable_path): if "Safari Technology Preview" in executable_path: @@ -55,7 +60,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH, self.quiet = quiet log = PIPE if quiet: - log = open(os.devnull, 'w', encoding='utf-8') + log = open(os.devnull, "w", encoding="utf-8") super().__init__(executable_path, port, log) def command_line_args(self): diff --git a/py/selenium/webdriver/safari/webdriver.py b/py/selenium/webdriver/safari/webdriver.py index d035380e128c1..67a4a4660ac2e 100644 --- a/py/selenium/webdriver/safari/webdriver.py +++ b/py/selenium/webdriver/safari/webdriver.py @@ -36,9 +36,18 @@ class WebDriver(RemoteWebDriver): """ - def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_service=False, - desired_capabilities=DEFAULT_SAFARI_CAPS, quiet=False, - keep_alive=True, service_args=None, options: Options = None, service: Service = None): + def __init__( + self, + port=0, + executable_path=DEFAULT_EXECUTABLE_PATH, + reuse_service=False, + desired_capabilities=DEFAULT_SAFARI_CAPS, + quiet=False, + keep_alive=True, + service_args=None, + options: Options = None, + service: Service = None, + ): """ Creates a new Safari driver instance and launches or finds a running safaridriver service. @@ -55,28 +64,45 @@ def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_servic - service - Service object for handling the browser driver if you need to pass extra details """ if port: - warnings.warn("port has been deprecated, please set it via the service class", - DeprecationWarning, stacklevel=2) + warnings.warn( + "port has been deprecated, please set it via the service class", DeprecationWarning, stacklevel=2 + ) if executable_path != DEFAULT_EXECUTABLE_PATH: - warnings.warn("executable_path has been deprecated, please use the Options class to set it", - DeprecationWarning, stacklevel=2) + warnings.warn( + "executable_path has been deprecated, please use the Options class to set it", + DeprecationWarning, + stacklevel=2, + ) if reuse_service: - warnings.warn("reuse_service has been deprecated, please use the Service class to set it", - DeprecationWarning, stacklevel=2) + warnings.warn( + "reuse_service has been deprecated, please use the Service class to set it", + DeprecationWarning, + stacklevel=2, + ) if desired_capabilities != DEFAULT_SAFARI_CAPS: - warnings.warn("desired_capabilities has been deprecated, please use the Options class to set it", - DeprecationWarning, stacklevel=2) + warnings.warn( + "desired_capabilities has been deprecated, please use the Options class to set it", + DeprecationWarning, + stacklevel=2, + ) if quiet: - warnings.warn("quiet has been deprecated, please use the Service class to set it", - DeprecationWarning, stacklevel=2) + warnings.warn( + "quiet has been deprecated, please use the Service class to set it", DeprecationWarning, stacklevel=2 + ) if not keep_alive: - warnings.warn("keep_alive has been deprecated, please use the Service class to set it", - DeprecationWarning, stacklevel=2) + warnings.warn( + "keep_alive has been deprecated, please use the Service class to set it", + DeprecationWarning, + stacklevel=2, + ) if service_args: - warnings.warn("service_args has been deprecated, please use the Service class to set it", - DeprecationWarning, stacklevel=2) + warnings.warn( + "service_args has been deprecated, please use the Service class to set it", + DeprecationWarning, + stacklevel=2, + ) self._reuse_service = reuse_service if service: @@ -86,13 +112,9 @@ def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_servic if not reuse_service: self.service.start() - executor = SafariRemoteConnection(remote_server_addr=self.service.service_url, - keep_alive=keep_alive) + executor = SafariRemoteConnection(remote_server_addr=self.service.service_url, keep_alive=keep_alive) - super().__init__( - command_executor=executor, - options=options, - desired_capabilities=desired_capabilities) + super().__init__(command_executor=executor, options=options, desired_capabilities=desired_capabilities) self._is_remote = False diff --git a/py/tox.ini b/py/tox.ini index 3875eea77c963..6a4685e84967b 100644 --- a/py/tox.ini +++ b/py/tox.ini @@ -42,5 +42,5 @@ deps = flake8-typing-imports==1.13.0 commands = isort selenium/ test/ - black test/ selenium/common/ -l 120 + black test/ selenium/common/ selenium/webdriver/safari -l 120 flake8 selenium/ test/ --min-python-version=3.7