Skip to content
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
2 changes: 2 additions & 0 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def is_connected(self) -> bool:
async def new_context(
self,
viewport: ViewportSize = None,
screen: ViewportSize = None,
noViewport: bool = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
Expand Down Expand Up @@ -107,6 +108,7 @@ async def new_context(
async def new_page(
self,
viewport: ViewportSize = None,
screen: ViewportSize = None,
noViewport: bool = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async def launch_persistent_context(
downloadsPath: Union[str, Path] = None,
slowMo: float = None,
viewport: ViewportSize = None,
screen: ViewportSize = None,
noViewport: bool = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
Expand Down
15 changes: 15 additions & 0 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ async def continuation() -> Optional[Response]:

return EventContextManagerImpl(asyncio.create_task(continuation()))

async def wait_for_url(
self,
url: URLMatch,
wait_until: DocumentLoadState = None,
timeout: float = None,
) -> None:
matcher = URLMatcher(url)
if matcher.matches(self.url):
await self.wait_for_load_state(state=wait_until, timeout=timeout)
return
async with self.expect_navigation(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very odd alignment :/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whooops

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it isn't me though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

joke of the day: seems like black magic

url=url, wait_until=wait_until, timeout=timeout
):
pass

async def wait_for_load_state(
self, state: DocumentLoadState = None, timeout: float = None
) -> None:
Expand Down
8 changes: 8 additions & 0 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ async def wait_for_load_state(
) -> None:
return await self._main_frame.wait_for_load_state(**locals_to_params(locals()))

async def wait_for_url(
self,
url: URLMatch,
wait_until: DocumentLoadState = None,
timeout: float = None,
) -> None:
return await self._main_frame.wait_for_url(**locals_to_params(locals()))

async def wait_for_event(
self, event: str, predicate: Callable = None, timeout: float = None
) -> Any:
Expand Down
134 changes: 118 additions & 16 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ async def press(self, key: str, *, delay: float = None) -> NoneType:
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
texts.

Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When speficied with the
Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.

```py
Expand Down Expand Up @@ -1390,8 +1390,8 @@ async def dispatch_event(
) -> NoneType:
"""ElementHandle.dispatch_event

The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
is dispatched. This is equivalend to calling
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
`click` is dispatched. This is equivalent to calling
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).

```py
Expand Down Expand Up @@ -1948,7 +1948,7 @@ async def press(
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
texts.

Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When speficied with the
Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.

Parameters
Expand Down Expand Up @@ -2709,6 +2709,47 @@ def expect_navigation(
).future
)

async def wait_for_url(
self,
url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]],
*,
wait_until: Literal["domcontentloaded", "load", "networkidle"] = None,
timeout: float = None
) -> NoneType:
"""Frame.wait_for_url

Waits for the frame to navigate to the given URL.

```py
await frame.click(\"a.delayed-navigation\") # clicking the link will indirectly cause a navigation
await frame.wait_for_url(\"**/target.html\")
```

Parameters
----------
url : Union[Callable[[str], bool], Pattern, str]
A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
wait_until : Union["domcontentloaded", "load", "networkidle", NoneType]
When to consider operation succeeded, defaults to `load`. Events can be either:
- `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
- `'load'` - consider operation to be finished when the `load` event is fired.
- `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
timeout : Union[float, NoneType]
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
changed by using the `browser_context.set_default_navigation_timeout()`,
`browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or
`page.set_default_timeout()` methods.
"""

return mapping.from_maybe_impl(
await self._async(
"frame.wait_for_url",
self._impl_obj.wait_for_url(
url=self._wrap_handler(url), wait_until=wait_until, timeout=timeout
),
)
)

async def wait_for_load_state(
self,
state: Literal["domcontentloaded", "load", "networkidle"] = None,
Expand Down Expand Up @@ -3169,8 +3210,8 @@ async def dispatch_event(
) -> NoneType:
"""Frame.dispatch_event

The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
is dispatched. This is equivalend to calling
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
`click` is dispatched. This is equivalent to calling
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).

```py
Expand Down Expand Up @@ -4089,7 +4130,7 @@ async def press(
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
texts.

Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When speficied with the
Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.

Parameters
Expand Down Expand Up @@ -4894,6 +4935,7 @@ def set_default_navigation_timeout(self, timeout: float) -> NoneType:
- `page.reload()`
- `page.set_content()`
- `page.expect_navigation()`
- `page.wait_for_url()`

> NOTE: `page.set_default_navigation_timeout()` takes priority over `page.set_default_timeout()`,
`browser_context.set_default_timeout()` and `browser_context.set_default_navigation_timeout()`.
Expand Down Expand Up @@ -5210,8 +5252,8 @@ async def dispatch_event(
) -> NoneType:
"""Page.dispatch_event

The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
is dispatched. This is equivalend to calling
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
`click` is dispatched. This is equivalent to calling
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).

```py
Expand Down Expand Up @@ -5904,6 +5946,49 @@ async def wait_for_load_state(
)
)

async def wait_for_url(
self,
url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]],
*,
wait_until: Literal["domcontentloaded", "load", "networkidle"] = None,
timeout: float = None
) -> NoneType:
"""Page.wait_for_url

Waits for the main frame to navigate to the given URL.

```py
await page.click(\"a.delayed-navigation\") # clicking the link will indirectly cause a navigation
await page.wait_for_url(\"**/target.html\")
```

Shortcut for main frame's `frame.wait_for_url()`.

Parameters
----------
url : Union[Callable[[str], bool], Pattern, str]
A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
wait_until : Union["domcontentloaded", "load", "networkidle", NoneType]
When to consider operation succeeded, defaults to `load`. Events can be either:
- `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
- `'load'` - consider operation to be finished when the `load` event is fired.
- `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
timeout : Union[float, NoneType]
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
changed by using the `browser_context.set_default_navigation_timeout()`,
`browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or
`page.set_default_timeout()` methods.
"""

return mapping.from_maybe_impl(
await self._async(
"page.wait_for_url",
self._impl_obj.wait_for_url(
url=self._wrap_handler(url), wait_until=wait_until, timeout=timeout
),
)
)

async def wait_for_event(
self, event: str, predicate: typing.Callable = None, *, timeout: float = None
) -> typing.Any:
Expand Down Expand Up @@ -6163,7 +6248,7 @@ async def route(

> NOTE: The handler will only be called for the first url if the response is a redirect.

An example of a naïve handler that aborts all image requests:
An example of a naive handler that aborts all image requests:

```py
page = await browser.new_page()
Expand All @@ -6184,6 +6269,8 @@ async def route(
Page routes take precedence over browser context routes (set up with `browser_context.route()`) when request
matches both handlers.

To remove a route with its handler you can use `page.unroute()`.

> NOTE: Enabling routing disables http cache.

Parameters
Expand Down Expand Up @@ -6247,9 +6334,6 @@ async def screenshot(

Returns the buffer with the captured screenshot.

> NOTE: Screenshots take at least 1/6 second on Chromium OS X and Chromium Windows. See https://crbug.com/741689 for
discussion.

Parameters
----------
timeout : Union[float, NoneType]
Expand Down Expand Up @@ -7001,7 +7085,7 @@ async def press(
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
texts.

Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When speficied with the
Shortcuts such as `key: \"Control+o\"` or `key: \"Control+Shift+T\"` are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.

```py
Expand Down Expand Up @@ -8190,7 +8274,7 @@ async def route(
Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.

An example of a naïve handler that aborts all image requests:
An example of a naive handler that aborts all image requests:

```py
context = await browser.new_context()
Expand All @@ -8214,6 +8298,8 @@ async def route(
Page routes (set up with `page.route()`) take precedence over browser context routes when request matches both
handlers.

To remove a route with its handler you can use `browser_context.unroute()`.

> NOTE: Enabling routing disables http cache.

Parameters
Expand Down Expand Up @@ -8553,6 +8639,7 @@ async def new_context(
self,
*,
viewport: ViewportSize = None,
screen: ViewportSize = None,
no_viewport: bool = None,
ignore_https_errors: bool = None,
java_script_enabled: bool = None,
Expand Down Expand Up @@ -8595,6 +8682,9 @@ async def new_context(
----------
viewport : Union[{width: int, height: int}, NoneType]
Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed viewport.
screen : Union[{width: int, height: int}, NoneType]
Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the `viewport`
is set.
no_viewport : Union[bool, NoneType]
Does not enforce fixed viewport, allows resizing window in the headed mode.
ignore_https_errors : Union[bool, NoneType]
Expand Down Expand Up @@ -8666,6 +8756,7 @@ async def new_context(
"browser.new_context",
self._impl_obj.new_context(
viewport=viewport,
screen=screen,
noViewport=no_viewport,
ignoreHTTPSErrors=ignore_https_errors,
javaScriptEnabled=java_script_enabled,
Expand Down Expand Up @@ -8698,6 +8789,7 @@ async def new_page(
self,
*,
viewport: ViewportSize = None,
screen: ViewportSize = None,
no_viewport: bool = None,
ignore_https_errors: bool = None,
java_script_enabled: bool = None,
Expand Down Expand Up @@ -8735,6 +8827,9 @@ async def new_page(
----------
viewport : Union[{width: int, height: int}, NoneType]
Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed viewport.
screen : Union[{width: int, height: int}, NoneType]
Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the `viewport`
is set.
no_viewport : Union[bool, NoneType]
Does not enforce fixed viewport, allows resizing window in the headed mode.
ignore_https_errors : Union[bool, NoneType]
Expand Down Expand Up @@ -8806,6 +8901,7 @@ async def new_page(
"browser.new_page",
self._impl_obj.new_page(
viewport=viewport,
screen=screen,
noViewport=no_viewport,
ignoreHTTPSErrors=ignore_https_errors,
javaScriptEnabled=java_script_enabled,
Expand Down Expand Up @@ -8947,7 +9043,8 @@ async def launch(
resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox
or WebKit, use at your own risk.
channel : Union["chrome", "chrome-beta", "chrome-canary", "chrome-dev", "msedge", "msedge-beta", "msedge-canary", "msedge-dev", NoneType]
Browser distribution channel.
Browser distribution channel. Read more about using
[Google Chrome and Microsoft Edge](./browsers#google-chrome--microsoft-edge).
args : Union[List[str], NoneType]
Additional arguments to pass to the browser instance. The list of Chromium flags can be found
[here](http://peter.sh/experiments/chromium-command-line-switches/).
Expand Down Expand Up @@ -9043,6 +9140,7 @@ async def launch_persistent_context(
downloads_path: typing.Union[str, pathlib.Path] = None,
slow_mo: float = None,
viewport: ViewportSize = None,
screen: ViewportSize = None,
no_viewport: bool = None,
ignore_https_errors: bool = None,
java_script_enabled: bool = None,
Expand Down Expand Up @@ -9121,6 +9219,9 @@ async def launch_persistent_context(
Defaults to 0.
viewport : Union[{width: int, height: int}, NoneType]
Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed viewport.
screen : Union[{width: int, height: int}, NoneType]
Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the `viewport`
is set.
no_viewport : Union[bool, NoneType]
Does not enforce fixed viewport, allows resizing window in the headed mode.
ignore_https_errors : Union[bool, NoneType]
Expand Down Expand Up @@ -9201,6 +9302,7 @@ async def launch_persistent_context(
downloadsPath=downloads_path,
slowMo=slow_mo,
viewport=viewport,
screen=screen,
noViewport=no_viewport,
ignoreHTTPSErrors=ignore_https_errors,
javaScriptEnabled=java_script_enabled,
Expand Down
Loading