Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py] added type checks in setter methods of different browser options #12328

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions py/selenium/webdriver/chromium/options.py
Original file line number Diff line number Diff line change
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("Binary Location must be a string")
AutomatedTester marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 4 additions & 0 deletions py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
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("Binary Location must be a string")
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
Original file line number Diff line number Diff line change
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("Binary location must be a string")
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,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
Original file line number Diff line number Diff line change
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("Binary Location must be a string")
self._binary_location = value

def to_capabilities(self):
Expand Down