Skip to content

Commit

Permalink
[py] added type checks in setter methods of different browser optio…
Browse files Browse the repository at this point in the history
…ns (#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 <david.burns@theautomatedtester.co.uk>
  • Loading branch information
sandeepsuryaprasad and AutomatedTester committed Jul 26, 2023
1 parent d8b3418 commit 7c7790d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions py/selenium/webdriver/chromium/options.py
Expand Up @@ -51,6 +51,8 @@ def binary_location(self, value: str) -> None:
:Args:
- value: path to the Chromium binary
"""
if not isinstance(value, str):
raise TypeError(self.BINARY_LOCATION_ERROR)
self._binary_location = value

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

@property
Expand Down Expand Up @@ -162,6 +166,10 @@ def headless(self, value: bool) -> None:
stacklevel=2,
)
args = {"--headless"}

if not isinstance(value, bool):
raise TypeError("value must be a boolean")

if value:
self._arguments.extend(args)
else:
Expand Down
2 changes: 2 additions & 0 deletions py/selenium/webdriver/common/options.py
Expand Up @@ -372,6 +372,8 @@ def default_capabilities(self):


class ArgOptions(BaseOptions):
BINARY_LOCATION_ERROR = "Binary Location Must be a String"

def __init__(self) -> None:
super().__init__()
self._arguments = []
Expand Down
4 changes: 4 additions & 0 deletions py/selenium/webdriver/firefox/options.py
Expand Up @@ -67,6 +67,8 @@ def binary_location(self) -> str:
@binary_location.setter # noqa
def binary_location(self, value: str) -> None:
"""Sets the location of the browser binary by string."""
if not isinstance(value, str):
raise TypeError(self.BINARY_LOCATION_ERROR)
self.binary = value

@property
Expand Down Expand Up @@ -122,6 +124,8 @@ def headless(self, value: bool) -> None:
warnings.warn(
"headless property is deprecated, instead use add_argument('-headless')", DeprecationWarning, stacklevel=2
)
if not isinstance(value, bool):
raise TypeError("value must be a boolean")
if value:
self._arguments.append("-headless")
elif "-headless" in self._arguments:
Expand Down
8 changes: 8 additions & 0 deletions py/selenium/webdriver/safari/options.py
Expand Up @@ -59,6 +59,8 @@ def binary_location(self, value: str) -> None:
:Args:
- value : path to the browser binary
"""
if not isinstance(value, str):
raise TypeError(self.BINARY_LOCATION_ERROR)
self._binary_location = value

def to_capabilities(self) -> dict:
Expand Down Expand Up @@ -97,6 +99,8 @@ def automatic_inspection(self, value: bool) -> None:
:Args:
- value: boolean value
"""
if not isinstance(value, bool):
raise TypeError("Automatic Inspection must be a boolean")
self.set_capability(self.AUTOMATIC_INSPECTION, value)

@property
Expand All @@ -111,6 +115,8 @@ def automatic_profiling(self, value: bool) -> None:
:Args:
- value: boolean value
"""
if not isinstance(value, bool):
raise TypeError("Automatic Profiling must be a boolean")
self.set_capability(self.AUTOMATIC_PROFILING, value)

@property
Expand All @@ -126,4 +132,6 @@ def use_technology_preview(self, value: bool) -> None:
:Args:
- value: boolean value
"""
if not isinstance(value, bool):
raise TypeError("Use Technology Preview must be a boolean")
self.set_capability("browserName", self.SAFARI_TECH_PREVIEW if value else "safari")
2 changes: 2 additions & 0 deletions py/selenium/webdriver/safari/service.py
Expand Up @@ -68,4 +68,6 @@ def reuse_service(self) -> bool:

@reuse_service.setter
def reuse_service(self, reuse: bool) -> None:
if not isinstance(reuse, bool):
raise TypeError("reuse must be a boolean")
self._reuse_service = reuse
4 changes: 3 additions & 1 deletion py/selenium/webdriver/wpewebkit/options.py
Expand Up @@ -34,12 +34,14 @@ def binary_location(self) -> str:
return self._binary_location

@binary_location.setter
def binary_location(self, value) -> None:
def binary_location(self, value: str) -> None:
"""Allows you to set the browser binary to launch.
:Args:
- value : path to the browser binary
"""
if not isinstance(value, str):
raise TypeError(self.BINARY_LOCATION_ERROR)
self._binary_location = value

def to_capabilities(self):
Expand Down

0 comments on commit 7c7790d

Please sign in to comment.