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 1 commit
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
20 changes: 20 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,24 @@ 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:
self._update_subscription(event, True)
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved
super()._add_event_handler(event, k, v)

def remove_listener(self, event: str, f: Any) -> None:
super().remove_listener(event, f)
self._update_subscription(event, len(self.listeners(event)) > 0)
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved


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
6 changes: 3 additions & 3 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8499,7 +8499,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 +8544,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
6 changes: 3 additions & 3 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8534,7 +8534,7 @@ def go_forward(
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 @@ -8578,8 +8578,8 @@ 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
2 changes: 0 additions & 2 deletions scripts/documentation_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def print_entry(
) -> None:
if class_name in ["BindingCall"] or method_name in [
"pid",
"_add_event_handler",
"remove_listener",
]:
return
original_method_name = method_name
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
InWheel = None
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand

driver_version = "1.28.0-alpha-1667504282000"
driver_version = "1.28.0-alpha-nov-11-2022"


def extractall(zip: zipfile.ZipFile, path: str) -> None:
Expand Down
10 changes: 0 additions & 10 deletions tests/async/test_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,6 @@ async def test_fill_input_when_Node_is_removed(page, server):
assert await page.evaluate("result") == "some value"


async def test_clear_input(page: Page, server: Server) -> None:
await page.goto(server.PREFIX + "/input/textarea.html")
handle = await page.query_selector("input")
assert handle
await handle.fill("some value")
assert await page.evaluate("result") == "some value"
await handle.clear()
assert await page.evaluate("result") == ""


async def test_select_textarea(page, server, is_firefox):
await page.goto(server.PREFIX + "/input/textarea.html")
textarea = await page.query_selector("textarea")
Expand Down
30 changes: 0 additions & 30 deletions tests/async/test_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from playwright.async_api import Error, Page
from tests.server import Server


async def test_fill_textarea(page, server):
await page.goto(f"{server.PREFIX}/input/textarea.html")
Expand All @@ -28,28 +23,3 @@ async def test_fill_input(page, server):
await page.goto(f"{server.PREFIX}/input/textarea.html")
await page.fill("input", "some value")
assert await page.evaluate("result") == "some value"


async def test_should_throw_on_unsupported_inputs_when_clear(
page: Page, server: Server
):
await page.goto(f"{server.PREFIX}/input/textarea.html")
for type in ["button", "checkbox", "file", "image", "radio", "reset", "submit"]:
await page.eval_on_selector(
"input", "(input, type) => input.setAttribute('type', type)", type
)
with pytest.raises(Error) as exc_info:
await page.clear("input")
assert f'Input of type "{type}" cannot be filled' in exc_info.value.message


async def test_it_should_throw_nice_error_without_injected_script_stack_when_element_is_not_an_input_when_clear(
page: Page, server: Server
):
await page.goto(server.PREFIX + "/input/textarea.html")
with pytest.raises(Error) as exc_info:
await page.clear("body")
assert (
"Element is not an <input>, <textarea> or [contenteditable] element"
in exc_info.value.message
)
2 changes: 1 addition & 1 deletion tests/async/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ async def test_locator_frame_locator_should_throw_on_ambiguity(
button = page.locator("body").frame_locator("iframe").locator("button")
with pytest.raises(
Error,
match='.*strict mode violation: "body >> iframe" resolved to 3 elements.*',
match=r'.*strict mode violation: locator\("body"\)\.locator\("iframe"\) resolved to 3 elements.*',
):
await button.wait_for()

Expand Down
8 changes: 0 additions & 8 deletions tests/async/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,14 +1238,6 @@ async def test_fill_should_be_able_to_clear_using_fill(page, server):
assert await page.evaluate("result") == ""


async def test_fill_should_be_able_to_clear_using_clear(page, server):
await page.goto(server.PREFIX + "/input/textarea.html")
await page.fill("input", "some value")
assert await page.evaluate("result") == "some value"
await page.clear("input")
assert await page.evaluate("result") == ""


async def test_close_event_should_work_with_window_close(page, server):
async with page.expect_popup() as popup_info:
await page.evaluate("window['newPage'] = window.open('about:blank')")
Expand Down
1 change: 1 addition & 0 deletions tests/async/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async def test_should_not_error_if_page_not_closed_before_save_as(
):
page = await browser.new_page(record_video_dir=tmpdir)
await page.goto(server.PREFIX + "/grid.html")
await page.wait_for_timeout(1000) # make sure video has some data
out_path = tmpdir / "some-video.webm"
saved = page.video.save_as(out_path)
await page.close()
Expand Down
10 changes: 0 additions & 10 deletions tests/sync/test_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,6 @@ def test_fill_input_when_Node_is_removed(page: Page, server: Server) -> None:
assert page.evaluate("result") == "some value"


def test_clear_input(page: Page, server: Server) -> None:
page.goto(server.PREFIX + "/input/textarea.html")
handle = page.query_selector("input")
assert handle
handle.fill("some value")
assert page.evaluate("result") == "some value"
handle.clear()
assert page.evaluate("result") == ""


def test_select_textarea(page: Page, server: Server, is_firefox: bool) -> None:
page.goto(server.PREFIX + "/input/textarea.html")
textarea = page.query_selector("textarea")
Expand Down
29 changes: 1 addition & 28 deletions tests/sync/test_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from playwright.sync_api import Error, Page
from playwright.sync_api import Page
from tests.server import Server


Expand All @@ -28,28 +26,3 @@ def test_fill_input(page: Page, server: Server) -> None:
page.goto(f"{server.PREFIX}/input/textarea.html")
page.fill("input", "some value")
assert page.evaluate("result") == "some value"


def test_should_throw_on_unsupported_inputs_when_clear(
page: Page, server: Server
) -> None:
page.goto(f"{server.PREFIX}/input/textarea.html")
for type in ["button", "checkbox", "file", "image", "radio", "reset", "submit"]:
page.eval_on_selector(
"input", "(input, type) => input.setAttribute('type', type)", type
)
with pytest.raises(Error) as exc_info:
page.clear("input")
assert f'input of type "{type}" cannot be filled' in exc_info.value.message


def test_it_should_throw_nice_error_without_injected_script_stack_when_element_is_not_an_input_when_clear(
page: Page, server: Server
) -> None:
page.goto(server.PREFIX + "/input/textarea.html")
with pytest.raises(Error) as exc_info:
page.clear("body")
assert (
"Element is not an <input>, <textarea> or [contenteditable] element"
in exc_info.value.message
)
2 changes: 1 addition & 1 deletion tests/sync/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def test_locator_frame_locator_should_throw_on_ambiguity(
button = page.locator("body").frame_locator("iframe").locator("button")
with pytest.raises(
Error,
match='.*strict mode violation: "body >> iframe" resolved to 3 elements.*',
match=r'.*strict mode violation: locator\("body"\)\.locator\("iframe"\) resolved to 3 elements.*',
):
button.wait_for()

Expand Down
8 changes: 0 additions & 8 deletions tests/sync/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,3 @@ def test_emitted_for_domcontentloaded_and_load(page: Page, server: Server) -> No
page.goto(server.EMPTY_PAGE)
assert isinstance(dom_info.value, Page)
assert isinstance(load_info.value, Page)


def test_fill_should_be_able_to_clear_using_clear(page: Page, server: Server) -> None:
page.goto(server.PREFIX + "/input/textarea.html")
page.fill("input", "some value")
assert page.evaluate("result") == "some value"
page.clear("input")
assert page.evaluate("result") == ""