Skip to content

Commit 4fb9e07

Browse files
authored
chore: add dupe sync tests for 1.56 roll (#2988)
1 parent f4ad602 commit 4fb9e07

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

tests/sync/test_page_aria_snapshot.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,13 @@ def test_should_snapshot_with_restored_contain_mode_inside_deep_equal(
204204
- listitem: 1.1
205205
""",
206206
)
207+
208+
209+
def test_match_values_both_against_regex_and_string(page: Page) -> None:
210+
page.set_content('<a href="/auth?r=/">Log in</a>')
211+
expect(page.locator("body")).to_match_aria_snapshot(
212+
"""
213+
- link "Log in":
214+
- /url: /auth?r=/
215+
""",
216+
)
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+
16+
from playwright.sync_api import Page
17+
18+
19+
def test_console_messages_should_work(page: Page) -> None:
20+
page.evaluate(
21+
"""() => {
22+
for (let i = 0; i < 301; i++)
23+
console.log('message' + i);
24+
}"""
25+
)
26+
27+
messages = page.console_messages()
28+
objects = [{"text": m.text, "type": m.type, "page": m.page} for m in messages]
29+
30+
expected = []
31+
for i in range(201, 301):
32+
expected.append({"text": f"message{i}", "type": "log", "page": page})
33+
34+
assert len(objects) >= 100, "should be at least 100 messages"
35+
message_count = len(messages) - len(expected)
36+
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.sync_api import Page
16+
17+
18+
def test_page_errors_should_work(page: Page) -> None:
19+
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 = 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"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.sync_api import Page, Request, Route
16+
from tests.server import Server
17+
18+
19+
def test_should_return_last_requests(page: Page, server: Server) -> None:
20+
page.goto(server.PREFIX + "/title.html")
21+
for i in range(200):
22+
23+
def _handle_route(route: Route) -> None:
24+
route.fulfill(
25+
status=200,
26+
body=f"url:{route.request.url}",
27+
)
28+
29+
page.route(f"**/fetch?{i}", _handle_route)
30+
31+
# #0 is the navigation request, so start with #1.
32+
for i in range(1, 100):
33+
page.evaluate("url => fetch(url)", server.PREFIX + f"/fetch?{i}")
34+
first_100_requests_with_goto = page.requests()
35+
first_100_requests = first_100_requests_with_goto[1:]
36+
37+
for i in range(100, 200):
38+
page.evaluate("url => fetch(url)", server.PREFIX + f"/fetch?{i}")
39+
last_100_requests = page.requests()
40+
41+
all_requests = first_100_requests + last_100_requests
42+
43+
def gather_response(request: Request) -> dict:
44+
response = request.response()
45+
assert response
46+
return {"text": response.text(), "url": request.url}
47+
48+
# All 199 requests are fully functional.
49+
received = [gather_response(request) for request in all_requests]
50+
expected = []
51+
for i in range(1, 200):
52+
url = server.PREFIX + f"/fetch?{i}"
53+
expected.append({"url": url, "text": f"url:{url}"})
54+
assert received == expected

0 commit comments

Comments
 (0)