Skip to content

chore: roll Playwright to 0.170.0-next.1608058598043 #370

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

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 14 additions & 4 deletions playwright/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import sys
from pathlib import Path
from types import SimpleNamespace
from typing import TYPE_CHECKING, Dict, List, Union

Expand Down Expand Up @@ -94,13 +96,17 @@ async def newContext(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: StorageState = None,
storageState: Union[StorageState, str, Path] = None,
) -> BrowserContext:
params = locals_to_params(locals())
# Python is strict in which variables gets passed to methods. We get this
# value from the device descriptors, thats why we have to strip it out.
if "defaultBrowserType" in params:
if defaultBrowserType in params:
del params["defaultBrowserType"]
if storageState:
if not isinstance(storageState, dict):
with open(storageState, "r") as f:
params["storageState"] = json.load(f)
if viewport == 0:
del params["viewport"]
params["noDefaultViewport"] = True
Expand Down Expand Up @@ -143,13 +149,17 @@ async def newPage(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: StorageState = None,
storageState: Union[StorageState, str, Path] = None,
) -> Page:
params = locals_to_params(locals())
# Python is strict in which variables gets passed to methods. We get this
# value from the device descriptors, thats why we have to strip it out.
if "defaultBrowserType" in params:
if defaultBrowserType:
del params["defaultBrowserType"]
if storageState:
if not isinstance(storageState, dict):
with open(storageState, "r") as f:
params["storageState"] = json.load(f)
context = await self.newContext(**params)
page = await context.newPage()
page._owned_context = context
Expand Down
9 changes: 7 additions & 2 deletions playwright/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import asyncio
import json
from pathlib import Path
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
Expand Down Expand Up @@ -233,8 +234,12 @@ async def close(self) -> None:
if not is_safe_close_error(e):
raise e

async def storageState(self) -> StorageState:
return await self._channel.send_return_as_dict("storageState")
async def storageState(self, path: Union[str, Path] = None) -> StorageState:
result = await self._channel.send_return_as_dict("storageState")
if path:
with open(path, "w") as f:
json.dump(result, f)
return result

def expect_event(
self,
Expand Down
2 changes: 2 additions & 0 deletions playwright/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def _create_remote_object(
def _replace_channels_with_guids(self, payload: Any) -> Any:
if payload is None:
return payload
if isinstance(payload, Path):
return str(payload)
if isinstance(payload, list):
return list(map(lambda p: self._replace_channels_with_guids(p), payload))
if isinstance(payload, Channel):
Expand Down
5 changes: 3 additions & 2 deletions playwright/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import sys
from pathlib import Path
from typing import Dict, List, Optional, Union

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

class RecordHarOptions(TypedDict, total=False):
omitContent: Optional[bool]
path: str
path: Union[str, Path]


class RecordVideoOptions(TypedDict, total=False):
dir: str
dir: Union[str, Path]
size: Optional[IntSize]


Expand Down
62 changes: 34 additions & 28 deletions playwright/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,7 +2074,7 @@ async def waitForNavigation(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
url : Union[str, Pattern, Callable[[str], bool], NoneType]
URL string, URL regex pattern or predicate receiving URL to match while waiting for the navigation.
waitUntil : Optional[Literal['domcontentloaded', 'load', 'networkidle']]
When to consider operation succeeded, defaults to `load`. Events can be either:
Expand Down Expand Up @@ -3714,14 +3714,13 @@ def frame(
) -> typing.Union["Frame", NoneType]:
"""Page.frame

Returns frame matching the criteria. Returns `null` if no frame matches.
Returns frame matching the specified criteria. Either `name` or `url` must be specified.

Parameters
----------
name : Optional[str]
frame name specified in the `iframe`'s `name` attribute
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
url : Union[str, Pattern, Callable[[str], bool], NoneType]
A glob pattern, regex pattern or predicate receiving frame's `url` as a URL object.

Returns
Expand Down Expand Up @@ -4346,7 +4345,7 @@ async def waitForNavigation(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
url : Union[str, Pattern, Callable[[str], bool], NoneType]
A glob pattern, regex pattern or predicate receiving URL to match while waiting for the navigation.
waitUntil : Optional[Literal['domcontentloaded', 'load', 'networkidle']]
When to consider operation succeeded, defaults to `load`. Events can be either:
Expand Down Expand Up @@ -4378,7 +4377,7 @@ async def waitForRequest(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
url : Union[str, Pattern, Callable[[str], bool], NoneType]
Request URL string, regex or predicate receiving Request object.
timeout : Optional[int]
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.
Expand Down Expand Up @@ -4407,7 +4406,7 @@ async def waitForResponse(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool], NoneType]
url : Union[str, Pattern, Callable[[str], bool], NoneType]
Request URL string, regex or predicate receiving Response object.
timeout : Optional[int]
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.
Expand Down Expand Up @@ -4610,9 +4609,9 @@ async def route(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool]]
url : Union[str, Pattern, Callable[[str], bool]]
A glob pattern, regex pattern or predicate receiving URL to match while routing.
handler : typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]
handler : Callable[[Route, Request], Any]
handler function to route the request.
"""
return mapping.from_maybe_impl(
Expand All @@ -4632,9 +4631,9 @@ async def unroute(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool]]
url : Union[str, Pattern, Callable[[str], bool]]
A glob pattern, regex pattern or predicate receiving URL to match while routing.
handler : Optional[typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]]
handler : Optional[Callable[[Route, Request], Any]]
Optional handler function to route the request.
"""
return mapping.from_maybe_impl(
Expand Down Expand Up @@ -6139,9 +6138,9 @@ async def route(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool]]
url : Union[str, Pattern, Callable[[str], bool]]
A glob pattern, regex pattern or predicate receiving URL to match while routing.
handler : typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]
handler : Callable[[Route, Request], Any]
handler function to route the request.
"""
return mapping.from_maybe_impl(
Expand All @@ -6162,9 +6161,9 @@ async def unroute(

Parameters
----------
url : Union[str, Pattern, typing.Callable[[str], bool]]
url : Union[str, Pattern, Callable[[str], bool]]
A glob pattern, regex pattern or predicate receiving URL used to register a routing with browserContext.route(url, handler).
handler : Optional[typing.Callable[[playwright.network.Route, playwright.network.Request], typing.Any]]
handler : Optional[Callable[[Route, Request], Any]]
Optional handler function used to register a routing with browserContext.route(url, handler).
"""
return mapping.from_maybe_impl(
Expand Down Expand Up @@ -6208,16 +6207,23 @@ async def close(self) -> NoneType:
"""
return mapping.from_maybe_impl(await self._impl_obj.close())

async def storageState(self) -> StorageState:
async def storageState(
self, path: typing.Union[str, pathlib.Path] = None
) -> StorageState:
"""BrowserContext.storageState

Returns storage state for this browser context, contains current cookies and local storage snapshot.

Parameters
----------
path : Union[str, pathlib.Path, NoneType]
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.

Returns
-------
{"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]]}
"""
return mapping.from_maybe_impl(await self._impl_obj.storageState())
return mapping.from_maybe_impl(await self._impl_obj.storageState(path=path))

def expect_event(
self,
Expand Down Expand Up @@ -6427,7 +6433,7 @@ async def newContext(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: StorageState = None,
storageState: typing.Union[StorageState, str, pathlib.Path] = None,
) -> "BrowserContext":
"""Browser.newContext

Expand Down Expand Up @@ -6474,12 +6480,12 @@ async def newContext(
**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.
videoSize : Optional[{"width": int, "height": int}]
**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.
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
recordHar : Optional[{"omitContent": Optional[bool], "path": Union[str, pathlib.Path]}]
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.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
recordVideo : Optional[{"dir": Union[str, pathlib.Path], "size": Optional[{"width": int, "height": int}]}]
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.
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]]}]
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState().
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]
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:

Returns
-------
Expand Down Expand Up @@ -6539,7 +6545,7 @@ async def newPage(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: StorageState = None,
storageState: typing.Union[StorageState, str, pathlib.Path] = None,
) -> "Page":
"""Browser.newPage

Expand Down Expand Up @@ -6589,12 +6595,12 @@ async def newPage(
**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.
videoSize : Optional[{"width": int, "height": int}]
**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.
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
recordHar : Optional[{"omitContent": Optional[bool], "path": Union[str, pathlib.Path]}]
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.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
recordVideo : Optional[{"dir": Union[str, pathlib.Path], "size": Optional[{"width": int, "height": int}]}]
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.
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]]}]
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState().
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]
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:

Returns
-------
Expand Down Expand Up @@ -6879,9 +6885,9 @@ async def launchPersistentContext(
**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.
videoSize : Optional[{"width": int, "height": int}]
**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.
recordHar : Optional[{"omitContent": Optional[bool], "path": str}]
recordHar : Optional[{"omitContent": Optional[bool], "path": Union[str, pathlib.Path]}]
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.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
recordVideo : Optional[{"dir": Union[str, pathlib.Path], "size": Optional[{"width": int, "height": int}]}]
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.

Returns
Expand Down
Loading