Skip to content

Commit 5fdd334

Browse files
[py] Update docstrings to google pydoc format (#16511)
Co-authored-by: Corey Goldberg <[email protected]>
1 parent 189f556 commit 5fdd334

File tree

21 files changed

+1113
-1939
lines changed

21 files changed

+1113
-1939
lines changed

py/selenium/webdriver/common/actions/action_builder.py

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@ def __init__(
4949
def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]:
5050
"""Get the device with the given name.
5151
52-
Parameters:
53-
-----------
54-
name : str
55-
The name of the device to get.
52+
Args:
53+
name: The name of the device to get.
5654
5755
Returns:
58-
--------
59-
Optional[Union[WheelInput, PointerInput, KeyInput]] : The device with the given name.
56+
The device with the given name, or None if not found.
6057
"""
6158
return next(filter(lambda x: x == name, self.devices), None)
6259

@@ -83,19 +80,15 @@ def wheel_action(self) -> WheelActions:
8380
def add_key_input(self, name: str) -> KeyInput:
8481
"""Add a new key input device to the action builder.
8582
86-
Parameters:
87-
-----------
88-
name : str
89-
The name of the key input device.
83+
Args:
84+
name: The name of the key input device.
9085
9186
Returns:
92-
--------
93-
KeyInput : The newly created key input device.
87+
The newly created key input device.
9488
9589
Example:
96-
--------
97-
>>> action_builder = ActionBuilder(driver)
98-
>>> action_builder.add_key_input(name="keyboard2")
90+
>>> action_builder = ActionBuilder(driver)
91+
>>> action_builder.add_key_input(name="keyboard2")
9992
"""
10093
new_input = KeyInput(name)
10194
self._add_input(new_input)
@@ -104,25 +97,17 @@ def add_key_input(self, name: str) -> KeyInput:
10497
def add_pointer_input(self, kind: str, name: str) -> PointerInput:
10598
"""Add a new pointer input device to the action builder.
10699
107-
Parameters:
108-
-----------
109-
kind : str
110-
The kind of pointer input device.
111-
- "mouse"
112-
- "touch"
113-
- "pen"
114-
115-
name : str
116-
The name of the pointer input device.
100+
Args:
101+
kind: The kind of pointer input device. Valid values are "mouse",
102+
"touch", or "pen".
103+
name: The name of the pointer input device.
117104
118105
Returns:
119-
--------
120-
PointerInput : The newly created pointer input device.
106+
The newly created pointer input device.
121107
122108
Example:
123-
--------
124-
>>> action_builder = ActionBuilder(driver)
125-
>>> action_builder.add_pointer_input(kind="mouse", name="mouse")
109+
>>> action_builder = ActionBuilder(driver)
110+
>>> action_builder.add_pointer_input(kind="mouse", name="mouse")
126111
"""
127112
new_input = PointerInput(kind, name)
128113
self._add_input(new_input)
@@ -131,19 +116,15 @@ def add_pointer_input(self, kind: str, name: str) -> PointerInput:
131116
def add_wheel_input(self, name: str) -> WheelInput:
132117
"""Add a new wheel input device to the action builder.
133118
134-
Parameters:
135-
-----------
136-
name : str
137-
The name of the wheel input device.
119+
Args:
120+
name: The name of the wheel input device.
138121
139122
Returns:
140-
--------
141-
WheelInput : The newly created wheel input device.
123+
The newly created wheel input device.
142124
143125
Example:
144-
--------
145-
>>> action_builder = ActionBuilder(driver)
146-
>>> action_builder.add_wheel_input(name="wheel2")
126+
>>> action_builder = ActionBuilder(driver)
127+
>>> action_builder.add_wheel_input(name="wheel2")
147128
"""
148129
new_input = WheelInput(name)
149130
self._add_input(new_input)
@@ -153,11 +134,10 @@ def perform(self) -> None:
153134
"""Performs all stored actions.
154135
155136
Example:
156-
--------
157-
>>> action_builder = ActionBuilder(driver)
158-
>>> keyboard = action_builder.key_input
159-
>>> el = driver.find_element(id: "some_id")
160-
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys").perform()
137+
>>> action_builder = ActionBuilder(driver)
138+
>>> keyboard = action_builder.key_input
139+
>>> el = driver.find_element(id: "some_id")
140+
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys").perform()
161141
"""
162142
enc: dict[str, list[Any]] = {"actions": []}
163143
for device in self.devices:
@@ -171,21 +151,18 @@ def clear_actions(self) -> None:
171151
"""Clears actions that are already stored on the remote end.
172152
173153
Example:
174-
--------
175-
>>> action_builder = ActionBuilder(driver)
176-
>>> keyboard = action_builder.key_input
177-
>>> el = driver.find_element(By.ID, "some_id")
178-
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys")
179-
>>> action_builder.clear_actions()
154+
>>> action_builder = ActionBuilder(driver)
155+
>>> keyboard = action_builder.key_input
156+
>>> el = driver.find_element(By.ID, "some_id")
157+
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys")
158+
>>> action_builder.clear_actions()
180159
"""
181160
self.driver.execute(Command.W3C_CLEAR_ACTIONS)
182161

183162
def _add_input(self, new_input: Union[KeyInput, PointerInput, WheelInput]) -> None:
184163
"""Add a new input device to the action builder.
185164
186-
Parameters:
187-
-----------
188-
new_input : Union[KeyInput, PointerInput, WheelInput]
189-
The new input device to add.
165+
Args:
166+
new_input: The new input device to add.
190167
"""
191168
self.devices.append(new_input)

py/selenium/webdriver/common/bidi/browser.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def get_state(self) -> str:
5959
"""Gets the state of the client window.
6060
6161
Returns:
62-
-------
6362
str: The state of the client window (one of the ClientWindowState constants).
6463
"""
6564
return self.state
@@ -68,7 +67,6 @@ def get_client_window(self) -> str:
6867
"""Gets the client window identifier.
6968
7069
Returns:
71-
-------
7270
str: The client window identifier.
7371
"""
7472
return self.client_window
@@ -77,7 +75,6 @@ def get_width(self) -> int:
7775
"""Gets the width of the client window.
7876
7977
Returns:
80-
-------
8178
int: The width of the client window.
8279
"""
8380
return self.width
@@ -86,7 +83,6 @@ def get_height(self) -> int:
8683
"""Gets the height of the client window.
8784
8885
Returns:
89-
-------
9086
int: The height of the client window.
9187
"""
9288
return self.height
@@ -95,7 +91,6 @@ def get_x(self) -> int:
9591
"""Gets the x coordinate of the client window.
9692
9793
Returns:
98-
-------
9994
int: The x coordinate of the client window.
10095
"""
10196
return self.x
@@ -104,7 +99,6 @@ def get_y(self) -> int:
10499
"""Gets the y coordinate of the client window.
105100
106101
Returns:
107-
-------
108102
int: The y coordinate of the client window.
109103
"""
110104
return self.y
@@ -113,7 +107,6 @@ def is_active(self) -> bool:
113107
"""Checks if the client window is active.
114108
115109
Returns:
116-
-------
117110
bool: True if the client window is active, False otherwise.
118111
"""
119112
return self.active
@@ -122,16 +115,13 @@ def is_active(self) -> bool:
122115
def from_dict(cls, data: dict) -> "ClientWindowInfo":
123116
"""Creates a ClientWindowInfo instance from a dictionary.
124117
125-
Parameters:
126-
-----------
118+
Args:
127119
data: A dictionary containing the client window information.
128120
129121
Returns:
130-
-------
131122
ClientWindowInfo: A new instance of ClientWindowInfo.
132123
133124
Raises:
134-
------
135125
ValueError: If required fields are missing or have invalid types.
136126
"""
137127
try:
@@ -175,7 +165,7 @@ def from_dict(cls, data: dict) -> "ClientWindowInfo":
175165
active=active,
176166
)
177167
except (KeyError, TypeError) as e:
178-
raise ValueError(f"Invalid data format for ClientWindowInfo: {e}")
168+
raise ValueError(f"Invalid data format for ClientWindowInfo: {e}") from e
179169

180170

181171
class Browser:
@@ -194,14 +184,12 @@ def create_user_context(
194184
) -> str:
195185
"""Creates a new user context.
196186
197-
Parameters:
198-
-----------
199-
accept_insecure_certs: Optional flag to accept insecure TLS certificates
200-
proxy: Optional proxy configuration for the user context
201-
unhandled_prompt_behavior: Optional configuration for handling user prompts
187+
Args:
188+
accept_insecure_certs: Optional flag to accept insecure TLS certificates.
189+
proxy: Optional proxy configuration for the user context.
190+
unhandled_prompt_behavior: Optional configuration for handling user prompts.
202191
203192
Returns:
204-
-------
205193
str: The ID of the created user context.
206194
"""
207195
params: dict[str, Any] = {}
@@ -222,7 +210,6 @@ def get_user_contexts(self) -> list[str]:
222210
"""Gets all user contexts.
223211
224212
Returns:
225-
-------
226213
List[str]: A list of user context IDs.
227214
"""
228215
result = self.conn.execute(command_builder("browser.getUserContexts", {}))
@@ -231,16 +218,14 @@ def get_user_contexts(self) -> list[str]:
231218
def remove_user_context(self, user_context_id: str) -> None:
232219
"""Removes a user context.
233220
234-
Parameters:
235-
-----------
221+
Args:
236222
user_context_id: The ID of the user context to remove.
237223
238224
Raises:
239-
------
240-
Exception: If the user context ID is "default" or does not exist.
225+
ValueError: If the user context ID is "default" or does not exist.
241226
"""
242227
if user_context_id == "default":
243-
raise Exception("Cannot remove the default user context")
228+
raise ValueError("Cannot remove the default user context")
244229

245230
params = {"userContext": user_context_id}
246231
self.conn.execute(command_builder("browser.removeUserContext", params))
@@ -249,7 +234,6 @@ def get_client_windows(self) -> list[ClientWindowInfo]:
249234
"""Gets all client windows.
250235
251236
Returns:
252-
-------
253237
List[ClientWindowInfo]: A list of client window information.
254238
"""
255239
result = self.conn.execute(command_builder("browser.getClientWindows", {}))

0 commit comments

Comments
 (0)