Skip to content

Commit e6a7a37

Browse files
authored
chore(roll): roll Playwright to 1.34.3 (#1930)
1 parent 7a91855 commit e6a7a37

11 files changed

+360
-6
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
44

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->113.0.5672.53<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->114.0.5735.35<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> ||||
99
| Firefox <!-- GEN:firefox-version -->113.0<!-- GEN:stop --> ||||
1010

Diff for: playwright/_impl/_browser_context.py

+7
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,13 @@ async def wait_for_event(
478478
pass
479479
return await event_info
480480

481+
def expect_console_message(
482+
self,
483+
predicate: Callable[[ConsoleMessage], bool] = None,
484+
timeout: float = None,
485+
) -> EventContextManagerImpl[ConsoleMessage]:
486+
return self.expect_event(Page.Events.Console, predicate, timeout)
487+
481488
def expect_page(
482489
self,
483490
predicate: Callable[[Page], bool] = None,

Diff for: playwright/async_api/_generated.py

+32
Original file line numberDiff line numberDiff line change
@@ -13733,6 +13733,38 @@ async def wait_for_event(
1373313733
)
1373413734
)
1373513735

13736+
def expect_console_message(
13737+
self,
13738+
predicate: typing.Optional[typing.Callable[["ConsoleMessage"], bool]] = None,
13739+
*,
13740+
timeout: typing.Optional[float] = None
13741+
) -> AsyncEventContextManager["ConsoleMessage"]:
13742+
"""BrowserContext.expect_console_message
13743+
13744+
Performs action and waits for a `ConsoleMessage` to be logged by in the pages in the context. If predicate is
13745+
provided, it passes `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to
13746+
return a truthy value. Will throw an error if the page is closed before the `browser_context.on('console')` event
13747+
is fired.
13748+
13749+
Parameters
13750+
----------
13751+
predicate : Union[Callable[[ConsoleMessage], bool], None]
13752+
Receives the `ConsoleMessage` object and resolves to truthy value when the waiting should resolve.
13753+
timeout : Union[float, None]
13754+
Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The
13755+
default value can be changed by using the `browser_context.set_default_timeout()`.
13756+
13757+
Returns
13758+
-------
13759+
EventContextManager[ConsoleMessage]
13760+
"""
13761+
13762+
return AsyncEventContextManager(
13763+
self._impl_obj.expect_console_message(
13764+
predicate=self._wrap_handler(predicate), timeout=timeout
13765+
).future
13766+
)
13767+
1373613768
def expect_page(
1373713769
self,
1373813770
predicate: typing.Optional[typing.Callable[["Page"], bool]] = None,

Diff for: playwright/sync_api/_generated.py

+32
Original file line numberDiff line numberDiff line change
@@ -13799,6 +13799,38 @@ def wait_for_event(
1379913799
)
1380013800
)
1380113801

13802+
def expect_console_message(
13803+
self,
13804+
predicate: typing.Optional[typing.Callable[["ConsoleMessage"], bool]] = None,
13805+
*,
13806+
timeout: typing.Optional[float] = None
13807+
) -> EventContextManager["ConsoleMessage"]:
13808+
"""BrowserContext.expect_console_message
13809+
13810+
Performs action and waits for a `ConsoleMessage` to be logged by in the pages in the context. If predicate is
13811+
provided, it passes `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to
13812+
return a truthy value. Will throw an error if the page is closed before the `browser_context.on('console')` event
13813+
is fired.
13814+
13815+
Parameters
13816+
----------
13817+
predicate : Union[Callable[[ConsoleMessage], bool], None]
13818+
Receives the `ConsoleMessage` object and resolves to truthy value when the waiting should resolve.
13819+
timeout : Union[float, None]
13820+
Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The
13821+
default value can be changed by using the `browser_context.set_default_timeout()`.
13822+
13823+
Returns
13824+
-------
13825+
EventContextManager[ConsoleMessage]
13826+
"""
13827+
return EventContextManager(
13828+
self,
13829+
self._impl_obj.expect_console_message(
13830+
predicate=self._wrap_handler(predicate), timeout=timeout
13831+
).future,
13832+
)
13833+
1380213834
def expect_page(
1380313835
self,
1380413836
predicate: typing.Optional[typing.Callable[["Page"], bool]] = None,

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
InWheel = None
3131
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand
3232

33-
driver_version = "1.34.0-alpha-may-17-2023"
33+
driver_version = "1.34.3"
3434

3535

3636
def extractall(zip: zipfile.ZipFile, path: str) -> None:

Diff for: tests/async/test_browsercontext.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
import re
1617
from urllib.parse import urlparse
1718

1819
import pytest
@@ -477,13 +478,13 @@ def handler(route, request, ordinal):
477478
def handler4(route, request):
478479
handler(route, request, 4)
479480

480-
await context.route("**/empty.html", handler4)
481+
await context.route(re.compile("empty.html"), handler4)
481482

482483
await page.goto(server.EMPTY_PAGE)
483484
assert intercepted == [4]
484485

485486
intercepted = []
486-
await context.unroute("**/empty.html", handler4)
487+
await context.unroute(re.compile("empty.html"), handler4)
487488
await page.goto(server.EMPTY_PAGE)
488489
assert intercepted == [3]
489490

Diff for: tests/async/test_browsercontext_events.py

+8
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ def handle_route(request: HttpRequestWithPostBody) -> None:
180180
await dialog.accept("hello")
181181
await promise
182182
await popup.evaluate("window.result") == "hello"
183+
184+
185+
async def test_console_event_should_work_with_context_manager(page: Page) -> None:
186+
async with page.context.expect_console_message() as cm_info:
187+
await page.evaluate("() => console.log('hello')")
188+
message = await cm_info.value
189+
assert message.text == "hello"
190+
assert message.page == page

Diff for: tests/async/test_interception.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import asyncio
1616
import json
17+
import re
1718

1819
import pytest
1920

@@ -75,13 +76,13 @@ def handler4(route):
7576
intercepted.append(4)
7677
asyncio.create_task(route.continue_())
7778

78-
await page.route("**/empty.html", handler4)
79+
await page.route(re.compile("empty.html"), handler4)
7980

8081
await page.goto(server.EMPTY_PAGE)
8182
assert intercepted == [4]
8283

8384
intercepted = []
84-
await page.unroute("**/empty.html", handler4)
85+
await page.unroute(re.compile("empty.html"), handler4)
8586
await page.goto(server.EMPTY_PAGE)
8687
assert intercepted == [3]
8788

Diff for: tests/sync/test_browsercontext_events.py

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Copyright (c) Microsoft Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Optional
16+
17+
import pytest
18+
19+
from playwright.sync_api import Dialog, Page
20+
21+
from ..server import HttpRequestWithPostBody, Server
22+
23+
24+
def test_console_event_should_work(page: Page) -> None:
25+
with page.context.expect_console_message() as console_info:
26+
page.evaluate("() => console.log('hello')")
27+
message = console_info.value
28+
assert message.text == "hello"
29+
assert message.page == page
30+
31+
32+
def test_console_event_should_work_in_popup(page: Page) -> None:
33+
with page.context.expect_console_message() as console_info:
34+
with page.expect_popup() as popup_info:
35+
page.evaluate(
36+
"""() => {
37+
const win = window.open('');
38+
win.console.log('hello');
39+
}"""
40+
)
41+
message = console_info.value
42+
popup = popup_info.value
43+
assert message.text == "hello"
44+
assert message.page == popup
45+
46+
47+
# console message from javascript: url is not reported at all
48+
@pytest.mark.skip_browser("firefox")
49+
def test_console_event_should_work_in_popup_2(page: Page, browser_name: str) -> None:
50+
with page.context.expect_console_message(
51+
lambda msg: msg.type == "log"
52+
) as console_info:
53+
with page.context.expect_page() as page_info:
54+
page.evaluate(
55+
"""async () => {
56+
const win = window.open('javascript:console.log("hello")');
57+
await new Promise(f => setTimeout(f, 0));
58+
win.close();
59+
}"""
60+
)
61+
message = console_info.value
62+
popup = page_info.value
63+
assert message.text == "hello"
64+
assert message.page == popup
65+
66+
67+
# console message from javascript: url is not reported at all
68+
@pytest.mark.skip_browser("firefox")
69+
def test_console_event_should_work_in_immediately_closed_popup(
70+
page: Page, browser_name: str
71+
) -> None:
72+
with page.context.expect_console_message(
73+
lambda msg: msg.type == "log"
74+
) as console_info:
75+
with page.context.expect_page() as page_info:
76+
page.evaluate(
77+
"""() => {
78+
const win = window.open('');
79+
win.console.log('hello');
80+
win.close();
81+
}"""
82+
)
83+
message = console_info.value
84+
popup = page_info.value
85+
assert message.text == "hello"
86+
assert message.page == popup
87+
88+
89+
def test_dialog_event_should_work1(page: Page) -> None:
90+
dialog1: Optional[Dialog] = None
91+
92+
def handle_page_dialog(dialog: Dialog) -> None:
93+
nonlocal dialog1
94+
dialog1 = dialog
95+
dialog.accept("hello")
96+
97+
page.on("dialog", handle_page_dialog)
98+
99+
dialog2: Optional[Dialog] = None
100+
101+
def handle_context_dialog(dialog: Dialog) -> None:
102+
nonlocal dialog2
103+
dialog2 = dialog
104+
105+
page.context.on("dialog", handle_context_dialog)
106+
107+
assert page.evaluate("() => prompt('hey?')") == "hello"
108+
assert dialog1
109+
assert dialog1 == dialog2
110+
assert dialog1.message == "hey?"
111+
assert dialog1.page == page
112+
113+
114+
def test_dialog_event_should_work_in_popup1(page: Page) -> None:
115+
dialog: Optional[Dialog] = None
116+
117+
def handle_dialog(d: Dialog) -> None:
118+
nonlocal dialog
119+
dialog = d
120+
dialog.accept("hello")
121+
122+
page.context.on("dialog", handle_dialog)
123+
124+
with page.expect_popup() as popup_info:
125+
assert page.evaluate("() => window.open('').prompt('hey?')") == "hello"
126+
popup = popup_info.value
127+
assert dialog
128+
assert dialog.message == "hey?"
129+
assert dialog.page == popup
130+
131+
132+
# console message from javascript: url is not reported at all
133+
@pytest.mark.skip_browser("firefox")
134+
def test_dialog_event_should_work_in_popup_2(page: Page, browser_name: str) -> None:
135+
def handle_dialog(dialog: Dialog) -> None:
136+
assert dialog.message == "hey?"
137+
assert dialog.page is None
138+
dialog.accept("hello")
139+
140+
page.context.on("dialog", handle_dialog)
141+
142+
assert page.evaluate("() => window.open('javascript:prompt(\"hey?\")')")
143+
144+
145+
# console message from javascript: url is not reported at all
146+
@pytest.mark.skip_browser("firefox")
147+
def test_dialog_event_should_work_in_immdiately_closed_popup(page: Page) -> None:
148+
popup = None
149+
150+
def handle_popup(p: Page) -> None:
151+
nonlocal popup
152+
popup = p
153+
154+
page.on("popup", handle_popup)
155+
156+
with page.context.expect_console_message() as console_info:
157+
page.evaluate(
158+
"""() => {
159+
const win = window.open();
160+
win.console.log('hello');
161+
win.close();
162+
}"""
163+
)
164+
message = console_info.value
165+
166+
assert message.text == "hello"
167+
assert message.page == popup
168+
169+
170+
def test_dialog_event_should_work_with_inline_script_tag(
171+
page: Page, server: Server
172+
) -> None:
173+
def handle_route(request: HttpRequestWithPostBody) -> None:
174+
request.setHeader("content-type", "text/html")
175+
request.write(b"""<script>window.result = prompt('hey?')</script>""")
176+
request.finish()
177+
178+
server.set_route("/popup.html", handle_route)
179+
page.goto(server.EMPTY_PAGE)
180+
page.set_content("<a href='popup.html' target=_blank>Click me</a>")
181+
182+
def handle_dialog(dialog: Dialog) -> None:
183+
assert dialog.message == "hey?"
184+
assert dialog.page == popup
185+
dialog.accept("hello")
186+
187+
page.context.on("dialog", handle_dialog)
188+
189+
with page.expect_popup() as popup_info:
190+
page.click("a")
191+
popup = popup_info.value
192+
assert popup.evaluate("window.result") == "hello"
193+
194+
195+
def test_console_event_should_work_with_context_manager(page: Page) -> None:
196+
with page.context.expect_console_message() as cm_info:
197+
page.evaluate("() => console.log('hello')")
198+
message = cm_info.value
199+
assert message.text == "hello"
200+
assert message.page == page

Diff for: tests/sync/test_locators.py

+19
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,25 @@ def test_should_support_locator_filter(page: Page) -> None:
863863
expect(page.locator("div").filter(has_not_text="foo")).to_have_count(2)
864864

865865

866+
def test_locators_should_support_locator_and(page: Page) -> None:
867+
page.set_content(
868+
"""
869+
<div data-testid=foo>hello</div><div data-testid=bar>world</div>
870+
<span data-testid=foo>hello2</span><span data-testid=bar>world2</span>
871+
"""
872+
)
873+
expect(page.locator("div").and_(page.locator("div"))).to_have_count(2)
874+
expect(page.locator("div").and_(page.get_by_test_id("foo"))).to_have_text(["hello"])
875+
expect(page.locator("div").and_(page.get_by_test_id("bar"))).to_have_text(["world"])
876+
expect(page.get_by_test_id("foo").and_(page.locator("div"))).to_have_text(["hello"])
877+
expect(page.get_by_test_id("bar").and_(page.locator("span"))).to_have_text(
878+
["world2"]
879+
)
880+
expect(
881+
page.locator("span").and_(page.get_by_test_id(re.compile("bar|foo")))
882+
).to_have_count(2)
883+
884+
866885
def test_locators_has_does_not_encode_unicode(page: Page, server: Server) -> None:
867886
page.goto(server.EMPTY_PAGE)
868887
locators = [

0 commit comments

Comments
 (0)