Skip to content

Commit 345dc10

Browse files
authored
chore: roll Playwright to 0.170.0-next.1608058598043 (microsoft#370)
1 parent 2e59d30 commit 345dc10

11 files changed

+183
-69
lines changed

playwright/_browser.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516
import sys
17+
from pathlib import Path
1618
from types import SimpleNamespace
1719
from typing import TYPE_CHECKING, Dict, List, Union
1820

@@ -94,13 +96,17 @@ async def newContext(
9496
videoSize: IntSize = None,
9597
recordHar: RecordHarOptions = None,
9698
recordVideo: RecordVideoOptions = None,
97-
storageState: StorageState = None,
99+
storageState: Union[StorageState, str, Path] = None,
98100
) -> BrowserContext:
99101
params = locals_to_params(locals())
100102
# Python is strict in which variables gets passed to methods. We get this
101103
# value from the device descriptors, thats why we have to strip it out.
102-
if "defaultBrowserType" in params:
104+
if defaultBrowserType in params:
103105
del params["defaultBrowserType"]
106+
if storageState:
107+
if not isinstance(storageState, dict):
108+
with open(storageState, "r") as f:
109+
params["storageState"] = json.load(f)
104110
if viewport == 0:
105111
del params["viewport"]
106112
params["noDefaultViewport"] = True
@@ -143,13 +149,17 @@ async def newPage(
143149
videoSize: IntSize = None,
144150
recordHar: RecordHarOptions = None,
145151
recordVideo: RecordVideoOptions = None,
146-
storageState: StorageState = None,
152+
storageState: Union[StorageState, str, Path] = None,
147153
) -> Page:
148154
params = locals_to_params(locals())
149155
# Python is strict in which variables gets passed to methods. We get this
150156
# value from the device descriptors, thats why we have to strip it out.
151-
if "defaultBrowserType" in params:
157+
if defaultBrowserType:
152158
del params["defaultBrowserType"]
159+
if storageState:
160+
if not isinstance(storageState, dict):
161+
with open(storageState, "r") as f:
162+
params["storageState"] = json.load(f)
153163
context = await self.newContext(**params)
154164
page = await context.newPage()
155165
page._owned_context = context

playwright/_browser_context.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
import json
1617
from pathlib import Path
1718
from types import SimpleNamespace
1819
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
@@ -233,8 +234,12 @@ async def close(self) -> None:
233234
if not is_safe_close_error(e):
234235
raise e
235236

236-
async def storageState(self) -> StorageState:
237-
return await self._channel.send_return_as_dict("storageState")
237+
async def storageState(self, path: Union[str, Path] = None) -> StorageState:
238+
result = await self._channel.send_return_as_dict("storageState")
239+
if path:
240+
with open(path, "w") as f:
241+
json.dump(result, f)
242+
return result
238243

239244
def expect_event(
240245
self,

playwright/_connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def _create_remote_object(
231231
def _replace_channels_with_guids(self, payload: Any) -> Any:
232232
if payload is None:
233233
return payload
234+
if isinstance(payload, Path):
235+
return str(payload)
234236
if isinstance(payload, list):
235237
return list(map(lambda p: self._replace_channels_with_guids(p), payload))
236238
if isinstance(payload, Channel):

playwright/_types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import sys
16+
from pathlib import Path
1617
from typing import Dict, List, Optional, Union
1718

1819
if sys.version_info >= (3, 8): # pragma: no cover
@@ -119,11 +120,11 @@ class PdfMargins(TypedDict, total=False):
119120

120121
class RecordHarOptions(TypedDict, total=False):
121122
omitContent: Optional[bool]
122-
path: str
123+
path: Union[str, Path]
123124

124125

125126
class RecordVideoOptions(TypedDict, total=False):
126-
dir: str
127+
dir: Union[str, Path]
127128
size: Optional[IntSize]
128129

129130

playwright/async_api.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ async def waitForNavigation(
20742074
20752075
Parameters
20762076
----------
2077-
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
2077+
url : Union[str, Pattern, Callable[[str], bool], NoneType]
20782078
URL string, URL regex pattern or predicate receiving URL to match while waiting for the navigation.
20792079
waitUntil : Optional[Literal['domcontentloaded', 'load', 'networkidle']]
20802080
When to consider operation succeeded, defaults to `load`. Events can be either:
@@ -3714,14 +3714,13 @@ def frame(
37143714
) -> typing.Union["Frame", NoneType]:
37153715
"""Page.frame
37163716
3717-
Returns frame matching the criteria. Returns `null` if no frame matches.
37183717
Returns frame matching the specified criteria. Either `name` or `url` must be specified.
37193718
37203719
Parameters
37213720
----------
37223721
name : Optional[str]
37233722
frame name specified in the `iframe`'s `name` attribute
3724-
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
3723+
url : Union[str, Pattern, Callable[[str], bool], NoneType]
37253724
A glob pattern, regex pattern or predicate receiving frame's `url` as a URL object.
37263725
37273726
Returns
@@ -4346,7 +4345,7 @@ async def waitForNavigation(
43464345
43474346
Parameters
43484347
----------
4349-
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
4348+
url : Union[str, Pattern, Callable[[str], bool], NoneType]
43504349
A glob pattern, regex pattern or predicate receiving URL to match while waiting for the navigation.
43514350
waitUntil : Optional[Literal['domcontentloaded', 'load', 'networkidle']]
43524351
When to consider operation succeeded, defaults to `load`. Events can be either:
@@ -4378,7 +4377,7 @@ async def waitForRequest(
43784377
43794378
Parameters
43804379
----------
4381-
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
4380+
url : Union[str, Pattern, Callable[[str], bool], NoneType]
43824381
Request URL string, regex or predicate receiving Request object.
43834382
timeout : Optional[int]
43844383
Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the page.setDefaultTimeout(timeout) method.
@@ -4407,7 +4406,7 @@ async def waitForResponse(
44074406
44084407
Parameters
44094408
----------
4410-
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
4409+
url : Union[str, Pattern, Callable[[str], bool], NoneType]
44114410
Request URL string, regex or predicate receiving Response object.
44124411
timeout : Optional[int]
44134412
Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout) methods.
@@ -4610,9 +4609,9 @@ async def route(
46104609
46114610
Parameters
46124611
----------
4613-
url : Union[str, Pattern, typing.Callable[[str], bool]]
4612+
url : Union[str, Pattern, Callable[[str], bool]]
46144613
A glob pattern, regex pattern or predicate receiving URL to match while routing.
4615-
handler : typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]
4614+
handler : Callable[[Route, Request], Any]
46164615
handler function to route the request.
46174616
"""
46184617
return mapping.from_maybe_impl(
@@ -4632,9 +4631,9 @@ async def unroute(
46324631
46334632
Parameters
46344633
----------
4635-
url : Union[str, Pattern, typing.Callable[[str], bool]]
4634+
url : Union[str, Pattern, Callable[[str], bool]]
46364635
A glob pattern, regex pattern or predicate receiving URL to match while routing.
4637-
handler : Optional[typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]]
4636+
handler : Optional[Callable[[Route, Request], Any]]
46384637
Optional handler function to route the request.
46394638
"""
46404639
return mapping.from_maybe_impl(
@@ -6139,9 +6138,9 @@ async def route(
61396138
61406139
Parameters
61416140
----------
6142-
url : Union[str, Pattern, typing.Callable[[str], bool]]
6141+
url : Union[str, Pattern, Callable[[str], bool]]
61436142
A glob pattern, regex pattern or predicate receiving URL to match while routing.
6144-
handler : typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]
6143+
handler : Callable[[Route, Request], Any]
61456144
handler function to route the request.
61466145
"""
61476146
return mapping.from_maybe_impl(
@@ -6162,9 +6161,9 @@ async def unroute(
61626161
61636162
Parameters
61646163
----------
6165-
url : Union[str, Pattern, typing.Callable[[str], bool]]
6164+
url : Union[str, Pattern, Callable[[str], bool]]
61666165
A glob pattern, regex pattern or predicate receiving URL used to register a routing with browserContext.route(url, handler).
6167-
handler : Optional[typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]]
6166+
handler : Optional[Callable[[Route, Request], Any]]
61686167
Optional handler function used to register a routing with browserContext.route(url, handler).
61696168
"""
61706169
return mapping.from_maybe_impl(
@@ -6208,16 +6207,23 @@ async def close(self) -> NoneType:
62086207
"""
62096208
return mapping.from_maybe_impl(await self._impl_obj.close())
62106209

6211-
async def storageState(self) -> StorageState:
6210+
async def storageState(
6211+
self, path: typing.Union[str, pathlib.Path] = None
6212+
) -> StorageState:
62126213
"""BrowserContext.storageState
62136214
62146215
Returns storage state for this browser context, contains current cookies and local storage snapshot.
62156216
6217+
Parameters
6218+
----------
6219+
path : Union[str, pathlib.Path, NoneType]
6220+
The file path to save the storage state to. If `path` is a relative path, then it is resolved relative to current working directory. If no path is provided, storage state is still returned, but won't be saved to the disk.
6221+
62166222
Returns
62176223
-------
62186224
{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}
62196225
"""
6220-
return mapping.from_maybe_impl(await self._impl_obj.storageState())
6226+
return mapping.from_maybe_impl(await self._impl_obj.storageState(path=path))
62216227

62226228
def expect_event(
62236229
self,
@@ -6427,7 +6433,7 @@ async def newContext(
64276433
videoSize: IntSize = None,
64286434
recordHar: RecordHarOptions = None,
64296435
recordVideo: RecordVideoOptions = None,
6430-
storageState: StorageState = None,
6436+
storageState: typing.Union[StorageState, str, pathlib.Path] = None,
64316437
) -> "BrowserContext":
64326438
"""Browser.newContext
64336439
@@ -6474,12 +6480,12 @@ async def newContext(
64746480
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
64756481
videoSize : Optional[{"width": int, "height": int}]
64766482
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
6477-
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
6483+
recordHar : Optional[{"omitContent": Optional[bool], "path": Union[str, pathlib.Path]}]
64786484
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.
6479-
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
6485+
recordVideo : Optional[{"dir": Union[str, pathlib.Path], "size": Optional[{"width": int, "height": int}]}]
64806486
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
6481-
storageState : Optional[{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}]
6482-
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState().
6487+
storageState : Union[{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}, str, pathlib.Path, NoneType]
6488+
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState([options]). Either a path to the file with saved storage, or an object with the following fields:
64836489
64846490
Returns
64856491
-------
@@ -6539,7 +6545,7 @@ async def newPage(
65396545
videoSize: IntSize = None,
65406546
recordHar: RecordHarOptions = None,
65416547
recordVideo: RecordVideoOptions = None,
6542-
storageState: StorageState = None,
6548+
storageState: typing.Union[StorageState, str, pathlib.Path] = None,
65436549
) -> "Page":
65446550
"""Browser.newPage
65456551
@@ -6589,12 +6595,12 @@ async def newPage(
65896595
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
65906596
videoSize : Optional[{"width": int, "height": int}]
65916597
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
6592-
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
6598+
recordHar : Optional[{"omitContent": Optional[bool], "path": Union[str, pathlib.Path]}]
65936599
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.
6594-
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
6600+
recordVideo : Optional[{"dir": Union[str, pathlib.Path], "size": Optional[{"width": int, "height": int}]}]
65956601
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
6596-
storageState : Optional[{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}]
6597-
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState().
6602+
storageState : Union[{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}, str, pathlib.Path, NoneType]
6603+
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState([options]). Either a path to the file with saved storage, or an object with the following fields:
65986604
65996605
Returns
66006606
-------
@@ -6879,9 +6885,9 @@ async def launchPersistentContext(
68796885
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
68806886
videoSize : Optional[{"width": int, "height": int}]
68816887
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
6882-
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
6888+
recordHar : Optional[{"omitContent": Optional[bool], "path": Union[str, pathlib.Path]}]
68836889
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.
6884-
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
6890+
recordVideo : Optional[{"dir": Union[str, pathlib.Path], "size": Optional[{"width": int, "height": int}]}]
68856891
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
68866892
68876893
Returns

0 commit comments

Comments
 (0)