Skip to content

Commit

Permalink
[py]: Lint webdriver/safari/ in preparation for consolidating the d…
Browse files Browse the repository at this point in the history
…river API
  • Loading branch information
symonk committed Oct 1, 2022
1 parent f4a8915 commit 1c2f1cb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 41 deletions.
17 changes: 8 additions & 9 deletions py/selenium/webdriver/safari/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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")
8 changes: 4 additions & 4 deletions py/selenium/webdriver/safari/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
13 changes: 9 additions & 4 deletions py/selenium/webdriver/safari/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ 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
:Args:
- 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:
Expand All @@ -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):
Expand Down
68 changes: 45 additions & 23 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion py/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1c2f1cb

Please sign in to comment.