Skip to content

Commit 3295b24

Browse files
committed
Initial port of major changes
1 parent 6fa9500 commit 3295b24

File tree

10 files changed

+255
-50
lines changed

10 files changed

+255
-50
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
44

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->140.0.7339.16<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->141.0.7390.37<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->26.0<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->141.0<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->142.0.1<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

playwright/_impl/_glob.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,12 @@ def glob_to_regex_pattern(glob: str) -> str:
2828
tokens.append("\\" + char if char in escaped_chars else char)
2929
i += 1
3030
elif c == "*":
31-
before_deep = glob[i - 1] if i > 0 else None
3231
star_count = 1
3332
while i + 1 < len(glob) and glob[i + 1] == "*":
3433
star_count += 1
3534
i += 1
36-
after_deep = glob[i + 1] if i + 1 < len(glob) else None
37-
is_deep = (
38-
star_count > 1
39-
and (before_deep == "/" or before_deep is None)
40-
and (after_deep == "/" or after_deep is None)
41-
)
42-
if is_deep:
43-
tokens.append("((?:[^/]*(?:/|$))*)")
44-
i += 1
35+
if star_count > 1:
36+
tokens.append("(.*)")
4537
else:
4638
tokens.append("([^/]*)")
4739
else:

playwright/_impl/_page.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
async_writefile,
8080
locals_to_params,
8181
make_dirs_for_file,
82+
parse_error,
8283
serialize_error,
8384
url_matches,
8485
)
@@ -1434,6 +1435,23 @@ async def remove_locator_handler(self, locator: "Locator") -> None:
14341435
{"uid": uid},
14351436
)
14361437

1438+
async def requests(self) -> List[Request]:
1439+
request_objects = await self._channel.send("requests", None)
1440+
return [from_channel(r) for r in request_objects]
1441+
1442+
async def console_messages(self) -> List[ConsoleMessage]:
1443+
message_dicts = await self._channel.send("consoleMessages", None)
1444+
return [
1445+
ConsoleMessage(
1446+
{**event, "page": self._channel}, self._loop, self._dispatcher_fiber
1447+
)
1448+
for event in message_dicts
1449+
]
1450+
1451+
async def page_errors(self) -> List[Error]:
1452+
error_objects = await self._channel.send("pageErrors", None)
1453+
return [parse_error(error["error"]) for error in error_objects]
1454+
14371455

14381456
class Worker(ChannelOwner):
14391457
Events = SimpleNamespace(Close="close")

playwright/async_api/_generated.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12254,6 +12254,49 @@ async def remove_locator_handler(self, locator: "Locator") -> None:
1225412254
await self._impl_obj.remove_locator_handler(locator=locator._impl_obj)
1225512255
)
1225612256

12257+
async def requests(self) -> typing.List["Request"]:
12258+
"""Page.requests
12259+
12260+
Returns up to (currently) 100 last network request from this page. See `page.on('request')` for more details.
12261+
12262+
Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory
12263+
growth as new requests come in. Once collected, retrieving most information about the request is impossible.
12264+
12265+
Note that requests reported through the `page.on('request')` request are not collected, so there is a trade off
12266+
between efficient memory usage with `page.requests()` and the amount of available information reported
12267+
through `page.on('request')`.
12268+
12269+
Returns
12270+
-------
12271+
List[Request]
12272+
"""
12273+
12274+
return mapping.from_impl_list(await self._impl_obj.requests())
12275+
12276+
async def console_messages(self) -> typing.List["ConsoleMessage"]:
12277+
"""Page.console_messages
12278+
12279+
Returns up to (currently) 200 last console messages from this page. See `page.on('console')` for more details.
12280+
12281+
Returns
12282+
-------
12283+
List[ConsoleMessage]
12284+
"""
12285+
12286+
return mapping.from_impl_list(await self._impl_obj.console_messages())
12287+
12288+
async def page_errors(self) -> typing.List["Error"]:
12289+
"""Page.page_errors
12290+
12291+
Returns up to (currently) 200 last page errors from this page. See `page.on('page_error')` for more details.
12292+
12293+
Returns
12294+
-------
12295+
List[Error]
12296+
"""
12297+
12298+
return mapping.from_impl_list(await self._impl_obj.page_errors())
12299+
1225712300

1225812301
mapping.register(PageImpl, Page)
1225912302

@@ -12297,13 +12340,7 @@ def on(
1229712340
f: typing.Callable[["Page"], "typing.Union[typing.Awaitable[None], None]"],
1229812341
) -> None:
1229912342
"""
12300-
**NOTE** Only works with Chromium browser's persistent context.
12301-
12302-
Emitted when new background page is created in the context.
12303-
12304-
```py
12305-
background_page = await context.wait_for_event(\"backgroundpage\")
12306-
```"""
12343+
This event is not emitted."""
1230712344

1230812345
@typing.overload
1230912346
def on(
@@ -12477,13 +12514,7 @@ def once(
1247712514
f: typing.Callable[["Page"], "typing.Union[typing.Awaitable[None], None]"],
1247812515
) -> None:
1247912516
"""
12480-
**NOTE** Only works with Chromium browser's persistent context.
12481-
12482-
Emitted when new background page is created in the context.
12483-
12484-
```py
12485-
background_page = await context.wait_for_event(\"backgroundpage\")
12486-
```"""
12517+
This event is not emitted."""
1248712518

1248812519
@typing.overload
1248912520
def once(
@@ -12679,9 +12710,7 @@ def browser(self) -> typing.Optional["Browser"]:
1267912710
def background_pages(self) -> typing.List["Page"]:
1268012711
"""BrowserContext.background_pages
1268112712

12682-
**NOTE** Background pages are only supported on Chromium-based browsers.
12683-
12684-
All existing background pages in the context.
12713+
Returns an empty list.
1268512714

1268612715
Returns
1268712716
-------
@@ -16617,7 +16646,7 @@ def and_(self, locator: "Locator") -> "Locator":
1661716646
The following example finds a button with a specific title.
1661816647

1661916648
```py
16620-
button = page.get_by_role(\"button\").and_(page.getByTitle(\"Subscribe\"))
16649+
button = page.get_by_role(\"button\").and_(page.get_by_title(\"Subscribe\"))
1662116650
```
1662216651

1662316652
Parameters

playwright/sync_api/_generated.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12342,6 +12342,49 @@ def remove_locator_handler(self, locator: "Locator") -> None:
1234212342
self._sync(self._impl_obj.remove_locator_handler(locator=locator._impl_obj))
1234312343
)
1234412344

12345+
def requests(self) -> typing.List["Request"]:
12346+
"""Page.requests
12347+
12348+
Returns up to (currently) 100 last network request from this page. See `page.on('request')` for more details.
12349+
12350+
Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory
12351+
growth as new requests come in. Once collected, retrieving most information about the request is impossible.
12352+
12353+
Note that requests reported through the `page.on('request')` request are not collected, so there is a trade off
12354+
between efficient memory usage with `page.requests()` and the amount of available information reported
12355+
through `page.on('request')`.
12356+
12357+
Returns
12358+
-------
12359+
List[Request]
12360+
"""
12361+
12362+
return mapping.from_impl_list(self._sync(self._impl_obj.requests()))
12363+
12364+
def console_messages(self) -> typing.List["ConsoleMessage"]:
12365+
"""Page.console_messages
12366+
12367+
Returns up to (currently) 200 last console messages from this page. See `page.on('console')` for more details.
12368+
12369+
Returns
12370+
-------
12371+
List[ConsoleMessage]
12372+
"""
12373+
12374+
return mapping.from_impl_list(self._sync(self._impl_obj.console_messages()))
12375+
12376+
def page_errors(self) -> typing.List["Error"]:
12377+
"""Page.page_errors
12378+
12379+
Returns up to (currently) 200 last page errors from this page. See `page.on('page_error')` for more details.
12380+
12381+
Returns
12382+
-------
12383+
List[Error]
12384+
"""
12385+
12386+
return mapping.from_impl_list(self._sync(self._impl_obj.page_errors()))
12387+
1234512388

1234612389
mapping.register(PageImpl, Page)
1234712390

@@ -12383,13 +12426,7 @@ def on(
1238312426
self, event: Literal["backgroundpage"], f: typing.Callable[["Page"], "None"]
1238412427
) -> None:
1238512428
"""
12386-
**NOTE** Only works with Chromium browser's persistent context.
12387-
12388-
Emitted when new background page is created in the context.
12389-
12390-
```py
12391-
background_page = context.wait_for_event(\"backgroundpage\")
12392-
```"""
12429+
This event is not emitted."""
1239312430

1239412431
@typing.overload
1239512432
def on(
@@ -12529,13 +12566,7 @@ def once(
1252912566
self, event: Literal["backgroundpage"], f: typing.Callable[["Page"], "None"]
1253012567
) -> None:
1253112568
"""
12532-
**NOTE** Only works with Chromium browser's persistent context.
12533-
12534-
Emitted when new background page is created in the context.
12535-
12536-
```py
12537-
background_page = context.wait_for_event(\"backgroundpage\")
12538-
```"""
12569+
This event is not emitted."""
1253912570

1254012571
@typing.overload
1254112572
def once(
@@ -12701,9 +12732,7 @@ def browser(self) -> typing.Optional["Browser"]:
1270112732
def background_pages(self) -> typing.List["Page"]:
1270212733
"""BrowserContext.background_pages
1270312734

12704-
**NOTE** Background pages are only supported on Chromium-based browsers.
12705-
12706-
All existing background pages in the context.
12735+
Returns an empty list.
1270712736

1270812737
Returns
1270912738
-------
@@ -16680,7 +16709,7 @@ def and_(self, locator: "Locator") -> "Locator":
1668016709
The following example finds a button with a specific title.
1668116710

1668216711
```py
16683-
button = page.get_by_role(\"button\").and_(page.getByTitle(\"Subscribe\"))
16712+
button = page.get_by_role(\"button\").and_(page.get_by_title(\"Subscribe\"))
1668416713
```
1668516714

1668616715
Parameters

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import zipfile
2222
from typing import Dict
2323

24-
driver_version = "1.55.0-beta-1756314050000"
24+
driver_version = "1.56.0-beta-1759412259000"
2525

2626
base_wheel_bundles = [
2727
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 playwright._impl._page import Page
16+
17+
18+
async def test_console_messages_should_work(page: Page) -> None:
19+
await page.evaluate(
20+
"""() => {
21+
for (let i = 0; i < 301; i++)
22+
console.log('message' + i);
23+
}"""
24+
)
25+
26+
messages = await page.console_messages()
27+
objects = [{"text": m.text, "type": m.type, "page": m.page} for m in messages]
28+
29+
expected = []
30+
for i in range(201, 301):
31+
expected.append({"text": f"message{i}", "type": "log", "page": page})
32+
33+
assert len(objects) >= 100, "should be at least 100 messages"
34+
message_count = len(messages) - len(expected)
35+
assert objects[message_count:] == expected, "should return last messages"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 playwright.async_api import Page
16+
17+
18+
async def test_page_errors_should_work(page: Page) -> None:
19+
await page.evaluate(
20+
"""async () => {
21+
for (let i = 0; i < 301; i++)
22+
window.setTimeout(() => { throw new Error('error' + i); }, 0);
23+
await new Promise(f => window.setTimeout(f, 100));
24+
}"""
25+
)
26+
27+
errors = await page.page_errors()
28+
messages = [e.message for e in errors]
29+
30+
expected = []
31+
for i in range(201, 301):
32+
expected.append(f"error{i}")
33+
34+
assert len(messages) >= 100, "should be at least 100 errors"
35+
message_count = len(messages) - len(expected)
36+
assert messages[message_count:] == expected, "should return last errors"

0 commit comments

Comments
 (0)