Skip to content

Commit 203dadb

Browse files
Py safari options (#10385)
* Add safari options Include the Automatic Profiling and Automatic Inspection option to safarie options. Also add's the options to set browser name to Safari Technology Preview * Add safari options unit tests * Fix flake8 style error There where some blank lines containing whitespaces which is against the flake8 style convention. Co-authored-by: David Burns <[email protected]>
1 parent 63db6b8 commit 203dadb

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

py/selenium/webdriver/safari/options.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def to_capabilities(self) -> dict:
3131
class Options(ArgOptions):
3232
KEY = "safari.options"
3333

34+
# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
35+
AUTOMATIC_INSPECTION = 'safari:automaticInspection'
36+
AUTOMATIC_PROFILING = 'safari:automaticProfiling'
37+
38+
SAFARI_TECH_PREVIEW = 'Safari Technology Preview'
39+
3440
def __init__(self):
3541
super(Options, self).__init__()
3642
self._binary_location = None
@@ -78,3 +84,51 @@ def to_capabilities(self) -> dict:
7884
@property
7985
def default_capabilities(self) -> dict:
8086
return DesiredCapabilities.SAFARI.copy()
87+
88+
@property
89+
def automatic_inspection(self) -> bool:
90+
""":Returns: The option Automatic Inspection value """
91+
return self._caps.get(self.AUTOMATIC_INSPECTION)
92+
93+
@automatic_inspection.setter
94+
def automatic_inspection(self, value: bool):
95+
"""
96+
Sets the option Automatic Inspection to value
97+
98+
:Args:
99+
- value: boolean value
100+
101+
"""
102+
self.set_capability(self.AUTOMATIC_INSPECTION, value)
103+
104+
@property
105+
def automatic_profiling(self) -> bool:
106+
""":Returns: The options Automatic Profiling value """
107+
return self._caps.get(self.AUTOMATIC_PROFILING)
108+
109+
@automatic_profiling.setter
110+
def automatic_profiling(self, value: bool):
111+
"""
112+
Sets the option Automatic Profiling to value
113+
114+
:Args:
115+
- value: boolean value
116+
117+
"""
118+
self.set_capability(self.AUTOMATIC_PROFILING, value)
119+
120+
@property
121+
def use_technology_preview(self) -> bool:
122+
""":Returns: whether BROWSER_NAME is equal to Safari Technology Preview"""
123+
return self._caps.get('browserName') == self.SAFARI_TECH_PREVIEW
124+
125+
@use_technology_preview.setter
126+
def use_technology_preview(self, value: bool):
127+
"""
128+
Sets browser name to Safari Technology Preview if value else to safari.
129+
130+
:Args:
131+
- value: boolean value
132+
133+
"""
134+
self.set_capability('browserName', self.SAFARI_TECH_PREVIEW if value else 'safari')

py/test/unit/selenium/webdriver/safari/safari_options_tests.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,27 @@ def test_starts_with_default_capabilities(options):
5555
def test_is_a_baseoptions(options):
5656
from selenium.webdriver.common.options import BaseOptions
5757
assert isinstance(options, BaseOptions)
58+
59+
60+
def test_can_set_automatic_inspection(options):
61+
options.automatic_inspection = True
62+
assert options.automatic_inspection is True
63+
assert options._caps.get(Options.AUTOMATIC_INSPECTION) is True
64+
65+
66+
def test_can_set_automatic_profiling(options):
67+
options.automatic_profiling = True
68+
assert options.automatic_profiling is True
69+
assert options._caps.get(Options.AUTOMATIC_PROFILING) is True
70+
71+
72+
def test_setting_technology_preview_changes_browser_name(options):
73+
from selenium.webdriver import DesiredCapabilities
74+
BROWSER_NAME = 'browserName'
75+
assert options._caps.get(BROWSER_NAME) == DesiredCapabilities.SAFARI[BROWSER_NAME]
76+
77+
options.use_technology_preview = True
78+
assert options._caps.get(BROWSER_NAME) == options.SAFARI_TECH_PREVIEW
79+
80+
options.use_technology_preview = False
81+
assert options._caps.get(BROWSER_NAME) == DesiredCapabilities.SAFARI[BROWSER_NAME]

0 commit comments

Comments
 (0)