Skip to content
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

chore(roll): roll Playwright to 1.28.0-alpha-nov-11-2022 #1642

Merged
merged 3 commits into from
Nov 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->108.0.5359.22<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->108.0.5359.29<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->16.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->106.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

Expand Down
8 changes: 8 additions & 0 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ def __init__(
self.once(
self.Events.Close, lambda context: self._closed_future.set_result(True)
)
self._set_event_to_subscription_mapping(
{
BrowserContext.Events.Request: "request",
BrowserContext.Events.Response: "response",
BrowserContext.Events.RequestFinished: "requestFinished",
BrowserContext.Events.RequestFailed: "requestFailed",
}
)

def __repr__(self) -> str:
return f"<BrowserContext browser={self.browser}>"
Expand Down
22 changes: 22 additions & 0 deletions playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def __init__(
if self._parent:
self._parent._objects[guid] = self

self._event_to_subscription_mapping: Dict[str, str] = {}

def _dispose(self) -> None:
# Clean up from parent and connection.
if self._parent:
Expand All @@ -135,6 +137,26 @@ def _adopt(self, child: "ChannelOwner") -> None:
self._objects[child._guid] = child
child._parent = self

def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None:
self._event_to_subscription_mapping = mapping

def _update_subscription(self, event: str, enabled: bool) -> None:
protocol_event = self._event_to_subscription_mapping.get(event)
if protocol_event:
self._channel.send_no_reply(
"updateSubscription", {"event": protocol_event, "enabled": enabled}
)

def _add_event_handler(self, event: str, k: Any, v: Any) -> None:
if not self.listeners(event):
self._update_subscription(event, True)
super()._add_event_handler(event, k, v)

def remove_listener(self, event: str, f: Any) -> None:
super().remove_listener(event, f)
if not self.listeners(event):
self._update_subscription(event, False)


class ProtocolCallback:
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
Expand Down
8 changes: 0 additions & 8 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,6 @@ async def type(
) -> None:
await self._channel.send("type", locals_to_params(locals()))

async def clear(
self,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
) -> None:
await self.fill("", **locals_to_params(locals()))

async def press(
self,
key: str,
Expand Down
17 changes: 0 additions & 17 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,22 +794,5 @@ async def set_checked(
trial=trial,
)

async def clear(
self,
selector: str,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
strict: bool = None,
) -> None:
await self.fill(
selector,
"",
timeout=timeout,
noWaitAfter=noWaitAfter,
force=force,
strict=strict,
)

async def _highlight(self, selector: str) -> None:
await self._channel.send("highlight", {"selector": selector})
45 changes: 13 additions & 32 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ def __init__(
else None,
)

self._set_event_to_subscription_mapping(
{
Page.Events.Request: "request",
Page.Events.Response: "response",
Page.Events.RequestFinished: "requestFinished",
Page.Events.RequestFailed: "requestFailed",
Page.Events.FileChooser: "fileChooser",
}
)

def __repr__(self) -> str:
return f"<Page url={self.url!r}>"

Expand Down Expand Up @@ -294,20 +304,6 @@ def _on_video(self, params: Any) -> None:
artifact = from_channel(params["artifact"])
cast(Video, self.video)._artifact_ready(artifact)

def _add_event_handler(self, event: str, k: Any, v: Any) -> None:
if event == Page.Events.FileChooser and len(self.listeners(event)) == 0:
self._channel.send_no_reply(
"setFileChooserInterceptedNoReply", {"intercepted": True}
)
super()._add_event_handler(event, k, v)

def remove_listener(self, event: str, f: Any) -> None:
super().remove_listener(event, f)
if event == Page.Events.FileChooser and len(self.listeners(event)) == 0:
self._channel.send_no_reply(
"setFileChooserInterceptedNoReply", {"intercepted": False}
)

@property
def context(self) -> "BrowserContext":
return self._browser_context
Expand Down Expand Up @@ -545,12 +541,14 @@ async def go_forward(

async def emulate_media(
self,
media: Literal["print", "screen"] = None,
media: Literal["null", "print", "screen"] = None,
colorScheme: ColorScheme = None,
reducedMotion: ReducedMotion = None,
forcedColors: ForcedColors = None,
) -> None:
params = locals_to_params(locals())
if "media" in params:
params["media"] = "no-override" if params["media"] == "null" else media
if "colorScheme" in params:
params["colorScheme"] = (
"no-override" if params["colorScheme"] == "null" else colorScheme
Expand Down Expand Up @@ -741,23 +739,6 @@ async def fill(
) -> None:
return await self._main_frame.fill(**locals_to_params(locals()))

async def clear(
self,
selector: str,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
strict: bool = None,
) -> None:
await self.fill(
selector,
"",
timeout=timeout,
noWaitAfter=noWaitAfter,
force=force,
strict=strict,
)

def locator(
self,
selector: str,
Expand Down
139 changes: 3 additions & 136 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2228,42 +2228,6 @@ async def type(
)
)

async def clear(
self,
*,
timeout: typing.Optional[float] = None,
no_wait_after: typing.Optional[bool] = None,
force: typing.Optional[bool] = None
) -> None:
"""ElementHandle.clear

This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the element, clears it and triggers an
`input` event after clearing.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared
instead.

Parameters
----------
timeout : Union[float, None]
Maximum 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_timeout()` or `page.set_default_timeout()` methods.
no_wait_after : Union[bool, None]
Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
inaccessible pages. Defaults to `false`.
force : Union[bool, None]
Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`.
"""

return mapping.from_maybe_impl(
await self._impl_obj.clear(
timeout=timeout, noWaitAfter=no_wait_after, force=force
)
)

async def press(
self,
key: str,
Expand Down Expand Up @@ -5575,54 +5539,6 @@ async def set_checked(
)
)

async def clear(
self,
selector: str,
*,
timeout: typing.Optional[float] = None,
no_wait_after: typing.Optional[bool] = None,
force: typing.Optional[bool] = None,
strict: typing.Optional[bool] = None
) -> None:
"""Frame.clear

This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the
element, clears it and triggers an `input` event after clearing.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared
instead.

Parameters
----------
selector : str
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See
[working with selectors](../selectors.md) for more details.
timeout : Union[float, None]
Maximum 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_timeout()` or `page.set_default_timeout()` methods.
no_wait_after : Union[bool, None]
Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
inaccessible pages. Defaults to `false`.
force : Union[bool, None]
Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`.
strict : Union[bool, None]
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one
element, the call throws an exception.
"""

return mapping.from_maybe_impl(
await self._impl_obj.clear(
selector=selector,
timeout=timeout,
noWaitAfter=no_wait_after,
force=force,
strict=strict,
)
)


mapping.register(FrameImpl, Frame)

Expand Down Expand Up @@ -8499,7 +8415,7 @@ async def go_forward(
async def emulate_media(
self,
*,
media: typing.Optional[Literal["print", "screen"]] = None,
media: typing.Optional[Literal["null", "print", "screen"]] = None,
color_scheme: typing.Optional[
Literal["dark", "light", "no-preference", "null"]
] = None,
Expand Down Expand Up @@ -8544,8 +8460,8 @@ async def emulate_media(

Parameters
----------
media : Union["print", "screen", None]
Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null`
media : Union["null", "print", "screen", None]
Changes the CSS media type of the page. The only allowed values are `'Screen'`, `'Print'` and `'Null'`. Passing `'Null'`
disables CSS media emulation.
color_scheme : Union["dark", "light", "no-preference", "null", None]
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
Expand Down Expand Up @@ -9204,55 +9120,6 @@ async def fill(
)
)

async def clear(
self,
selector: str,
*,
timeout: typing.Optional[float] = None,
no_wait_after: typing.Optional[bool] = None,
force: typing.Optional[bool] = None,
strict: typing.Optional[bool] = None
) -> None:
"""Page.clear

This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the
element, clears it and triggers an `input` event after clearing. Note that you can pass an empty string to clear the
input field.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared
instead.

Parameters
----------
selector : str
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See
[working with selectors](../selectors.md) for more details.
timeout : Union[float, None]
Maximum 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_timeout()` or `page.set_default_timeout()` methods.
no_wait_after : Union[bool, None]
Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
inaccessible pages. Defaults to `false`.
force : Union[bool, None]
Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`.
strict : Union[bool, None]
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one
element, the call throws an exception.
"""

return mapping.from_maybe_impl(
await self._impl_obj.clear(
selector=selector,
timeout=timeout,
noWaitAfter=no_wait_after,
force=force,
strict=strict,
)
)

def locator(
self,
selector: str,
Expand Down