Skip to content

Commit 7c7790d

Browse files
[py] added type checks in setter methods of different browser options (#12328)
* [py] added type checks to setter methods in different browser options * [py] added type check validation in safari/services.py * [py] added cls variable to hold common error message * [py] added cls variable to hold common error message --------- Co-authored-by: David Burns <[email protected]>
1 parent d8b3418 commit 7c7790d

6 files changed

Lines changed: 27 additions & 1 deletion

File tree

py/selenium/webdriver/chromium/options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def binary_location(self, value: str) -> None:
5151
:Args:
5252
- value: path to the Chromium binary
5353
"""
54+
if not isinstance(value, str):
55+
raise TypeError(self.BINARY_LOCATION_ERROR)
5456
self._binary_location = value
5557

5658
@property
@@ -69,6 +71,8 @@ def debugger_address(self, value: str) -> None:
6971
:Args:
7072
- value: address of remote devtools instance if any (hostname[:port])
7173
"""
74+
if not isinstance(value, str):
75+
raise TypeError("Debugger Address must be a string")
7276
self._debugger_address = value
7377

7478
@property
@@ -162,6 +166,10 @@ def headless(self, value: bool) -> None:
162166
stacklevel=2,
163167
)
164168
args = {"--headless"}
169+
170+
if not isinstance(value, bool):
171+
raise TypeError("value must be a boolean")
172+
165173
if value:
166174
self._arguments.extend(args)
167175
else:

py/selenium/webdriver/common/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ def default_capabilities(self):
372372

373373

374374
class ArgOptions(BaseOptions):
375+
BINARY_LOCATION_ERROR = "Binary Location Must be a String"
376+
375377
def __init__(self) -> None:
376378
super().__init__()
377379
self._arguments = []

py/selenium/webdriver/firefox/options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def binary_location(self) -> str:
6767
@binary_location.setter # noqa
6868
def binary_location(self, value: str) -> None:
6969
"""Sets the location of the browser binary by string."""
70+
if not isinstance(value, str):
71+
raise TypeError(self.BINARY_LOCATION_ERROR)
7072
self.binary = value
7173

7274
@property
@@ -122,6 +124,8 @@ def headless(self, value: bool) -> None:
122124
warnings.warn(
123125
"headless property is deprecated, instead use add_argument('-headless')", DeprecationWarning, stacklevel=2
124126
)
127+
if not isinstance(value, bool):
128+
raise TypeError("value must be a boolean")
125129
if value:
126130
self._arguments.append("-headless")
127131
elif "-headless" in self._arguments:

py/selenium/webdriver/safari/options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def binary_location(self, value: str) -> None:
5959
:Args:
6060
- value : path to the browser binary
6161
"""
62+
if not isinstance(value, str):
63+
raise TypeError(self.BINARY_LOCATION_ERROR)
6264
self._binary_location = value
6365

6466
def to_capabilities(self) -> dict:
@@ -97,6 +99,8 @@ def automatic_inspection(self, value: bool) -> None:
9799
:Args:
98100
- value: boolean value
99101
"""
102+
if not isinstance(value, bool):
103+
raise TypeError("Automatic Inspection must be a boolean")
100104
self.set_capability(self.AUTOMATIC_INSPECTION, value)
101105

102106
@property
@@ -111,6 +115,8 @@ def automatic_profiling(self, value: bool) -> None:
111115
:Args:
112116
- value: boolean value
113117
"""
118+
if not isinstance(value, bool):
119+
raise TypeError("Automatic Profiling must be a boolean")
114120
self.set_capability(self.AUTOMATIC_PROFILING, value)
115121

116122
@property
@@ -126,4 +132,6 @@ def use_technology_preview(self, value: bool) -> None:
126132
:Args:
127133
- value: boolean value
128134
"""
135+
if not isinstance(value, bool):
136+
raise TypeError("Use Technology Preview must be a boolean")
129137
self.set_capability("browserName", self.SAFARI_TECH_PREVIEW if value else "safari")

py/selenium/webdriver/safari/service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ def reuse_service(self) -> bool:
6868

6969
@reuse_service.setter
7070
def reuse_service(self, reuse: bool) -> None:
71+
if not isinstance(reuse, bool):
72+
raise TypeError("reuse must be a boolean")
7173
self._reuse_service = reuse

py/selenium/webdriver/wpewebkit/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ def binary_location(self) -> str:
3434
return self._binary_location
3535

3636
@binary_location.setter
37-
def binary_location(self, value) -> None:
37+
def binary_location(self, value: str) -> None:
3838
"""Allows you to set the browser binary to launch.
3939
4040
:Args:
4141
- value : path to the browser binary
4242
"""
43+
if not isinstance(value, str):
44+
raise TypeError(self.BINARY_LOCATION_ERROR)
4345
self._binary_location = value
4446

4547
def to_capabilities(self):

0 commit comments

Comments
 (0)