Skip to content

Commit 2b329a9

Browse files
committed
Refactor docstrings for consistency and clarity across WebDriver and ChromiumOptions classes
1 parent 517c7e4 commit 2b329a9

File tree

4 files changed

+63
-61
lines changed

4 files changed

+63
-61
lines changed

py/selenium/webdriver/chrome/webdriver.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ def __init__(
3232
service: Optional[Service] = None,
3333
keep_alive: bool = True,
3434
) -> None:
35-
"""Creates a new instance of the chrome driver. Starts the service and
36-
then creates new instance of chrome driver.
35+
"""Creates a new instance of the chrome driver.
3736
38-
:Args:
39-
- options - this takes an instance of ChromeOptions
40-
- service - Service object for handling the browser driver if you need to pass extra details
41-
- keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
37+
Starts the service and then creates new instance of chrome driver.
38+
39+
Args:
40+
options: This takes an instance of ChromeOptions.
41+
service: Service object for handling the browser driver if you need to pass extra details.
42+
keep_alive: Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
4243
"""
4344
service = service if service else Service()
4445
options = options if options else Options()

py/selenium/webdriver/chromium/options.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ChromiumOptions(ArgOptions):
2727
KEY = "goog:chromeOptions"
2828

2929
def __init__(self) -> None:
30+
"""Initialize ChromiumOptions with default settings."""
3031
super().__init__()
3132
self._binary_location: str = ""
3233
self._extension_files: list[str] = []
@@ -37,42 +38,46 @@ def __init__(self) -> None:
3738

3839
@property
3940
def binary_location(self) -> str:
40-
""":Returns: The location of the binary, otherwise an empty string."""
41+
"""Returns:
42+
The location of the binary, otherwise an empty string.
43+
"""
4144
return self._binary_location
4245

4346
@binary_location.setter
4447
def binary_location(self, value: str) -> None:
4548
"""Allows you to set where the chromium binary lives.
4649
47-
Parameters:
48-
----------
49-
value: path to the Chromium binary
50+
Args:
51+
value: Path to the Chromium binary.
5052
"""
5153
if not isinstance(value, str):
5254
raise TypeError(self.BINARY_LOCATION_ERROR)
5355
self._binary_location = value
5456

5557
@property
5658
def debugger_address(self) -> Optional[str]:
57-
""":Returns: The address of the remote devtools instance."""
59+
"""Returns:
60+
The address of the remote devtools instance.
61+
"""
5862
return self._debugger_address
5963

6064
@debugger_address.setter
6165
def debugger_address(self, value: str) -> None:
6266
"""Allows you to set the address of the remote devtools instance that
6367
the ChromeDriver instance will try to connect to during an active wait.
6468
65-
Parameters:
66-
----------
67-
value: address of remote devtools instance if any (hostname[:port])
69+
Args:
70+
value: Address of remote devtools instance if any (hostname[:port]).
6871
"""
6972
if not isinstance(value, str):
7073
raise TypeError("Debugger Address must be a string")
7174
self._debugger_address = value
7275

7376
@property
7477
def extensions(self) -> list[str]:
75-
""":Returns: A list of encoded extensions that will be loaded."""
78+
"""Returns:
79+
A list of encoded extensions that will be loaded.
80+
"""
7681

7782
def _decode(file_data: BinaryIO) -> str:
7883
# Should not use base64.encodestring() which inserts newlines every
@@ -91,9 +96,8 @@ def add_extension(self, extension: str) -> None:
9196
"""Adds the path to the extension to a list that will be used to
9297
extract it to the ChromeDriver.
9398
94-
Parameters:
95-
----------
96-
extension: path to the \\*.crx file
99+
Args:
100+
extension: Path to the \\*.crx file.
97101
"""
98102
if extension:
99103
extension_to_add = os.path.abspath(os.path.expanduser(extension))
@@ -108,9 +112,8 @@ def add_encoded_extension(self, extension: str) -> None:
108112
"""Adds Base64 encoded string with extension data to a list that will
109113
be used to extract it to the ChromeDriver.
110114
111-
Parameters:
112-
----------
113-
extension: Base64 encoded string with extension data
115+
Args:
116+
extension: Base64 encoded string with extension data.
114117
"""
115118
if extension:
116119
self._extensions.append(extension)
@@ -119,45 +122,44 @@ def add_encoded_extension(self, extension: str) -> None:
119122

120123
@property
121124
def experimental_options(self) -> dict:
122-
""":Returns: A dictionary of experimental options for chromium."""
125+
"""Returns:
126+
A dictionary of experimental options for chromium.
127+
"""
123128
return self._experimental_options
124129

125130
def add_experimental_option(self, name: str, value: Union[str, int, dict, list[str]]) -> None:
126131
"""Adds an experimental option which is passed to chromium.
127132
128-
Parameters:
129-
----------
130-
name: The experimental option name.
131-
value: The option value.
133+
Args:
134+
name: The experimental option name.
135+
value: The option value.
132136
"""
133137
self._experimental_options[name] = value
134138

135139
@property
136140
def enable_webextensions(self) -> bool:
137-
""":Returns: Whether webextension support is enabled for Chromium-based browsers.
138-
True if webextension support is enabled, False otherwise.
141+
"""Returns:
142+
Whether webextension support is enabled for Chromium-based browsers.
143+
True if webextension support is enabled, False otherwise.
139144
"""
140145
return self._enable_webextensions
141146

142147
@enable_webextensions.setter
143148
def enable_webextensions(self, value: bool) -> None:
144149
"""Enables or disables webextension support for Chromium-based browsers.
145150
146-
Parameters:
147-
----------
148-
value : bool
149-
True to enable webextension support, False to disable.
151+
Args:
152+
value: True to enable webextension support, False to disable.
150153
151154
Notes:
152-
-----
153-
- When enabled, this automatically adds the required Chromium flags:
154-
- --enable-unsafe-extension-debugging
155-
- --remote-debugging-pipe
156-
- When disabled, this removes BOTH flags listed above, even if they were manually added via add_argument()
157-
before enabling webextensions.
158-
- Enabling --remote-debugging-pipe makes the connection b/w chromedriver
159-
and the browser use a pipe instead of a port, disabling many CDP functionalities
160-
like devtools
155+
- When enabled, this automatically adds the required Chromium flags:
156+
- --enable-unsafe-extension-debugging
157+
- --remote-debugging-pipe
158+
- When disabled, this removes BOTH flags listed above, even if they were manually added via add_argument()
159+
before enabling webextensions.
160+
- Enabling --remote-debugging-pipe makes the connection b/w chromedriver
161+
and the browser use a pipe instead of a port, disabling many CDP functionalities
162+
like devtools
161163
"""
162164
self._enable_webextensions = value
163165
if value:
@@ -174,11 +176,10 @@ def enable_webextensions(self, value: bool) -> None:
174176
self._arguments.remove(flag)
175177

176178
def to_capabilities(self) -> dict:
177-
"""Creates a capabilities with all the options that have been set
179+
"""Creates a capabilities with all the options that have been set.
178180
179181
Returns:
180-
-------
181-
dict : a dictionary with all set options
182+
A dictionary with all set options.
182183
"""
183184
caps = self._caps
184185
chrome_options = self.experimental_options.copy()

py/selenium/webdriver/firefox/firefox_binary.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class FirefoxBinary:
3434
def __init__(self, firefox_path=None, log_file=None):
3535
"""Creates a new instance of Firefox binary.
3636
37-
:Args:
38-
- firefox_path - Path to the Firefox executable. By default, it will be detected from the standard locations.
39-
- log_file - A file object to redirect the firefox process output to. It can be sys.stdout.
40-
Please note that with parallel run the output won't be synchronous.
41-
By default, it will be redirected to /dev/null.
37+
Args:
38+
firefox_path: Path to the Firefox executable. By default, it will be detected from the standard locations.
39+
log_file: A file object to redirect the firefox process output to. It can be sys.stdout.
40+
Please note that with parallel run the output won't be synchronous.
41+
By default, it will be redirected to /dev/null.
4242
"""
4343
self._start_cmd = firefox_path
4444
# We used to default to subprocess.PIPE instead of /dev/null, but after

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def __init__(
4444
"""Creates a new instance of the Firefox driver. Starts the service and
4545
then creates new instance of Firefox driver.
4646
47-
:Args:
48-
- options - Instance of ``options.Options``.
49-
- service - (Optional) service instance for managing the starting and stopping of the driver.
50-
- keep_alive - Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive.
47+
Args:
48+
options: Instance of ``options.Options``.
49+
service: (Optional) service instance for managing the starting and stopping of the driver.
50+
keep_alive: Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive.
5151
"""
5252

5353
self.service = service if service else Service()
@@ -159,11 +159,11 @@ def get_full_page_screenshot_as_file(self, filename) -> bool:
159159
image file. Returns False if there is any IOError, else returns True.
160160
Use full paths in your filename.
161161
162-
:Args:
163-
- filename: The full path you wish to save your screenshot to. This
164-
should end with a `.png` extension.
162+
Args:
163+
filename: The full path you wish to save your screenshot to. This
164+
should end with a `.png` extension.
165165
166-
:Usage:
166+
Usage:
167167
::
168168
169169
driver.get_full_page_screenshot_as_file("/Screenshots/foo.png")
@@ -188,11 +188,11 @@ def save_full_page_screenshot(self, filename) -> bool:
188188
image file. Returns False if there is any IOError, else returns True.
189189
Use full paths in your filename.
190190
191-
:Args:
192-
- filename: The full path you wish to save your screenshot to. This
193-
should end with a `.png` extension.
191+
Args:
192+
filename: The full path you wish to save your screenshot to. This
193+
should end with a `.png` extension.
194194
195-
:Usage:
195+
Usage:
196196
::
197197
198198
driver.save_full_page_screenshot("/Screenshots/foo.png")

0 commit comments

Comments
 (0)