Skip to content

Commit 576871d

Browse files
committed
Normalized timeout setting
1 parent 477e78b commit 576871d

File tree

8 files changed

+92
-168
lines changed

8 files changed

+92
-168
lines changed

playwright/_impl/_connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, connection: "Connection", object: "ChannelOwner") -> None:
5656
self._object = object
5757
self.on("error", lambda exc: self._connection._on_event_listener_error(exc))
5858
self._is_internal_type = False
59+
self._timeout_calculator: Optional[Callable[[Optional[float]], float]] = None
5960

6061
async def send(self, method: str, params: Dict = None) -> Any:
6162
return await self._connection.wrap_api_call(
@@ -82,6 +83,8 @@ async def _inner_send(
8283
) -> Any:
8384
if params is None:
8485
params = {}
86+
if self._timeout_calculator is not None:
87+
params["timeout"] = self._timeout_calculator(params.get("timeout"))
8588
if self._connection._error:
8689
error = self._connection._error
8790
self._connection._error = None
@@ -112,8 +115,10 @@ async def _inner_send(
112115
key = next(iter(result))
113116
return result[key]
114117

115-
def mark_as_internal_type(self) -> None:
116-
self._is_internal_type = True
118+
def _set_timeout_calculator(
119+
self, timeout_calculator: Callable[[Optional[float]], float]
120+
) -> None:
121+
self._timeout_calculator = timeout_calculator
117122

118123

119124
class ChannelOwner(AsyncIOEventEmitter):

playwright/_impl/_element_handle.py

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
) -> None:
5757
super().__init__(parent, type, guid, initializer)
5858
self._frame = cast("Frame", parent)
59+
self._channel._set_timeout_calculator(self._frame._timeout)
5960

6061
async def _createSelectorForTest(self, name: str) -> Optional[str]:
6162
return await self._channel.send("createSelectorForTest", dict(name=name))
@@ -105,9 +106,7 @@ async def dispatch_event(self, type: str, eventInit: Dict = None) -> None:
105106
)
106107

107108
async def scroll_into_view_if_needed(self, timeout: float = None) -> None:
108-
await self._channel.send(
109-
"scrollIntoViewIfNeeded", self._locals_to_params_with_timeout(locals())
110-
)
109+
await self._channel.send("scrollIntoViewIfNeeded", locals_to_params(locals()))
111110

112111
async def hover(
113112
self,
@@ -118,7 +117,7 @@ async def hover(
118117
force: bool = None,
119118
trial: bool = None,
120119
) -> None:
121-
await self._channel.send("hover", self._locals_to_params_with_timeout(locals()))
120+
await self._channel.send("hover", locals_to_params(locals()))
122121

123122
async def click(
124123
self,
@@ -132,7 +131,7 @@ async def click(
132131
noWaitAfter: bool = None,
133132
trial: bool = None,
134133
) -> None:
135-
await self._channel.send("click", self._locals_to_params_with_timeout(locals()))
134+
await self._channel.send("click", locals_to_params(locals()))
136135

137136
async def dblclick(
138137
self,
@@ -145,9 +144,7 @@ async def dblclick(
145144
noWaitAfter: bool = None,
146145
trial: bool = None,
147146
) -> None:
148-
await self._channel.send(
149-
"dblclick", self._locals_to_params_with_timeout(locals())
150-
)
147+
await self._channel.send("dblclick", locals_to_params(locals()))
151148

152149
async def select_option(
153150
self,
@@ -159,7 +156,7 @@ async def select_option(
159156
force: bool = None,
160157
noWaitAfter: bool = None,
161158
) -> List[str]:
162-
params = self._locals_to_params_with_timeout(
159+
params = locals_to_params(
163160
dict(
164161
timeout=timeout,
165162
force=force,
@@ -177,7 +174,7 @@ async def tap(
177174
noWaitAfter: bool = None,
178175
trial: bool = None,
179176
) -> None:
180-
await self._channel.send("tap", self._locals_to_params_with_timeout(locals()))
177+
await self._channel.send("tap", locals_to_params(locals()))
181178

182179
async def fill(
183180
self,
@@ -186,17 +183,13 @@ async def fill(
186183
noWaitAfter: bool = None,
187184
force: bool = None,
188185
) -> None:
189-
await self._channel.send("fill", self._locals_to_params_with_timeout(locals()))
186+
await self._channel.send("fill", locals_to_params(locals()))
190187

191188
async def select_text(self, force: bool = None, timeout: float = None) -> None:
192-
await self._channel.send(
193-
"selectText", self._locals_to_params_with_timeout(locals())
194-
)
189+
await self._channel.send("selectText", locals_to_params(locals()))
195190

196191
async def input_value(self, timeout: float = None) -> str:
197-
return await self._channel.send(
198-
"inputValue", self._locals_to_params_with_timeout(locals())
199-
)
192+
return await self._channel.send("inputValue", locals_to_params(locals()))
200193

201194
async def set_input_files(
202195
self,
@@ -228,7 +221,7 @@ async def type(
228221
timeout: float = None,
229222
noWaitAfter: bool = None,
230223
) -> None:
231-
await self._channel.send("type", self._locals_to_params_with_timeout(locals()))
224+
await self._channel.send("type", locals_to_params(locals()))
232225

233226
async def press(
234227
self,
@@ -237,7 +230,7 @@ async def press(
237230
timeout: float = None,
238231
noWaitAfter: bool = None,
239232
) -> None:
240-
await self._channel.send("press", self._locals_to_params_with_timeout(locals()))
233+
await self._channel.send("press", locals_to_params(locals()))
241234

242235
async def set_checked(
243236
self,
@@ -271,7 +264,7 @@ async def check(
271264
noWaitAfter: bool = None,
272265
trial: bool = None,
273266
) -> None:
274-
await self._channel.send("check", self._locals_to_params_with_timeout(locals()))
267+
await self._channel.send("check", locals_to_params(locals()))
275268

276269
async def uncheck(
277270
self,
@@ -281,9 +274,7 @@ async def uncheck(
281274
noWaitAfter: bool = None,
282275
trial: bool = None,
283276
) -> None:
284-
await self._channel.send(
285-
"uncheck", self._locals_to_params_with_timeout(locals())
286-
)
277+
await self._channel.send("uncheck", locals_to_params(locals()))
287278

288279
async def bounding_box(self) -> Optional[FloatRect]:
289280
return await self._channel.send("boundingBox")
@@ -302,7 +293,7 @@ async def screenshot(
302293
maskColor: str = None,
303294
style: str = None,
304295
) -> bytes:
305-
params = self._locals_to_params_with_timeout(locals())
296+
params = locals_to_params(locals())
306297
if "path" in params:
307298
del params["path"]
308299
if "mask" in params:
@@ -378,9 +369,7 @@ async def wait_for_element_state(
378369
],
379370
timeout: float = None,
380371
) -> None:
381-
await self._channel.send(
382-
"waitForElementState", self._locals_to_params_with_timeout(locals())
383-
)
372+
await self._channel.send("waitForElementState", locals_to_params(locals()))
384373

385374
async def wait_for_selector(
386375
self,
@@ -390,16 +379,9 @@ async def wait_for_selector(
390379
strict: bool = None,
391380
) -> Optional["ElementHandle"]:
392381
return from_nullable_channel(
393-
await self._channel.send(
394-
"waitForSelector", self._locals_to_params_with_timeout(locals())
395-
)
382+
await self._channel.send("waitForSelector", locals_to_params(locals()))
396383
)
397384

398-
def _locals_to_params_with_timeout(self, args: Dict) -> Dict:
399-
params = locals_to_params(args)
400-
params["timeout"] = self._frame._timeout(params.get("timeout"))
401-
return params
402-
403385

404386
def convert_select_option_values(
405387
value: Union[str, Sequence[str]] = None,

playwright/_impl/_fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
self._tracing: Tracing = from_channel(initializer["tracing"])
106106
self._close_reason: Optional[str] = None
107107
self._timeout_settings = TimeoutSettings(None)
108+
self._channel._set_timeout_calculator(self._timeout_settings.timeout)
108109

109110
async def dispose(self, reason: str = None) -> None:
110111
self._close_reason = reason
@@ -417,7 +418,6 @@ async def _inner_fetch(
417418
"jsonData": json_data,
418419
"formData": form_data,
419420
"multipartData": multipart_data,
420-
"timeout": self._timeout_settings.timeout(timeout),
421421
"failOnStatusCode": failOnStatusCode,
422422
"ignoreHTTPSErrors": ignoreHTTPSErrors,
423423
"maxRedirects": maxRedirects,

0 commit comments

Comments
 (0)