Skip to content

chore: roll Playwright to 1.25.0 #1494

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

Merged
merged 3 commits into from
Aug 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions playwright/_impl/_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from playwright._impl._api_structures import ExpectedTextValue, FrameExpectOptions
from playwright._impl._fetch import APIResponse
from playwright._impl._helper import is_textual_mime_type
from playwright._impl._locator import Locator
from playwright._impl._page import Page
from playwright._impl._str_utils import escape_regex_flags
Expand Down Expand Up @@ -594,6 +595,13 @@ async def to_be_ok(
log = "\n".join(log_list).strip()
if log:
message += f"\n Call log:\n{log}"

content_type = self._actual.headers.get("content-type")
is_text_encoding = content_type and is_textual_mime_type(content_type)
text = await self._actual.text() if is_text_encoding else None
if text is not None:
message += f"\n Response Text:\n{text[:1000]}"

raise AssertionError(message)

async def not_to_be_ok(self) -> None:
Expand Down
9 changes: 9 additions & 0 deletions playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,12 @@ def is_file_payload(value: Optional[Any]) -> bool:
and "mimeType" in value
and "buffer" in value
)


TEXTUAL_MIME_TYPE = re.compile(
r"^(text\/.*?|application\/(json|(x-)?javascript|xml.*?|ecmascript|graphql|x-www-form-urlencoded)|image\/svg(\+xml)?|application\/.*?(\+json|\+xml))(;\s*charset=.*)?$"
)


def is_textual_mime_type(mime_type: str) -> bool:
return bool(TEXTUAL_MIME_TYPE.match(mime_type))
8 changes: 8 additions & 0 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,10 @@ async def snapshot(
) -> typing.Optional[typing.Dict]:
"""Accessibility.snapshot

**DEPRECATED** This method is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
integration with Axe.

Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
page.

Expand Down Expand Up @@ -6233,6 +6237,10 @@ def once(
def accessibility(self) -> "Accessibility":
"""Page.accessibility

**DEPRECATED** This property is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
integration with Axe.

Returns
-------
Accessibility
Expand Down
8 changes: 8 additions & 0 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2827,6 +2827,10 @@ def snapshot(
) -> typing.Optional[typing.Dict]:
"""Accessibility.snapshot

**DEPRECATED** This method is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
integration with Axe.

Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
page.

Expand Down Expand Up @@ -6231,6 +6235,10 @@ def once(self, event: str, f: typing.Callable[..., None]) -> None:
def accessibility(self) -> "Accessibility":
"""Page.accessibility

**DEPRECATED** This property is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
integration with Axe.

Returns
-------
Accessibility
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.25.0-alpha-1660067092000"
driver_version = "1.25.0"


def extractall(zip: zipfile.ZipFile, path: str) -> None:
Expand Down
58 changes: 58 additions & 0 deletions tests/async/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,61 @@ async def test_assertions_response_is_ok_fail(page: Page, server: Server) -> Non
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/unknown") in error_message
assert "← 404 Not Found" in error_message


async def test_should_print_response_with_text_content_type_if_to_be_ok_fails(
page: Page, server: Server
) -> None:
server.set_route(
"/text-content-type",
lambda r: (
r.setResponseCode(404),
r.setHeader("content-type", "text/plain"),
r.write(b"Text error"),
r.finish(),
),
)
server.set_route(
"/no-content-type",
lambda r: (
r.setResponseCode(404),
r.write(b"No content type error"),
r.finish(),
),
)
server.set_route(
"/binary-content-type",
lambda r: (
r.setResponseCode(404),
r.setHeader("content-type", "image/bmp"),
r.write(b"Image content type error"),
r.finish(),
),
)

response = await page.request.get(server.PREFIX + "/text-content-type")
with pytest.raises(AssertionError) as excinfo:
await expect(response).to_be_ok()
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/text-content-type") in error_message
assert "← 404 Not Found" in error_message
assert "Response Text:" in error_message
assert "Text error" in error_message

response = await page.request.get(server.PREFIX + "/no-content-type")
with pytest.raises(AssertionError) as excinfo:
await expect(response).to_be_ok()
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/no-content-type") in error_message
assert "← 404 Not Found" in error_message
assert "Response Text:" not in error_message
assert "No content type error" not in error_message

response = await page.request.get(server.PREFIX + "/binary-content-type")
with pytest.raises(AssertionError) as excinfo:
await expect(response).to_be_ok()
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/binary-content-type") in error_message
assert "← 404 Not Found" in error_message
assert "Response Text:" not in error_message
assert "Image content type error" not in error_message
58 changes: 58 additions & 0 deletions tests/sync/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,61 @@ def test_assertions_response_is_ok_fail(page: Page, server: Server) -> None:
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/unknown") in error_message
assert "← 404 Not Found" in error_message


def test_should_print_response_with_text_content_type_if_to_be_ok_fails(
page: Page, server: Server
) -> None:
server.set_route(
"/text-content-type",
lambda r: (
r.setResponseCode(404),
r.setHeader("content-type", "text/plain"),
r.write(b"Text error"),
r.finish(),
),
)
server.set_route(
"/no-content-type",
lambda r: (
r.setResponseCode(404),
r.write(b"No content type error"),
r.finish(),
),
)
server.set_route(
"/binary-content-type",
lambda r: (
r.setResponseCode(404),
r.setHeader("content-type", "image/bmp"),
r.write(b"Image content type error"),
r.finish(),
),
)

response = page.request.get(server.PREFIX + "/text-content-type")
with pytest.raises(AssertionError) as excinfo:
expect(response).to_be_ok()
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/text-content-type") in error_message
assert "← 404 Not Found" in error_message
assert "Response Text:" in error_message
assert "Text error" in error_message

response = page.request.get(server.PREFIX + "/no-content-type")
with pytest.raises(AssertionError) as excinfo:
expect(response).to_be_ok()
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/no-content-type") in error_message
assert "← 404 Not Found" in error_message
assert "Response Text:" not in error_message
assert "No content type error" not in error_message

response = page.request.get(server.PREFIX + "/binary-content-type")
with pytest.raises(AssertionError) as excinfo:
expect(response).to_be_ok()
error_message = str(excinfo.value)
assert ("→ GET " + server.PREFIX + "/binary-content-type") in error_message
assert "← 404 Not Found" in error_message
assert "Response Text:" not in error_message
assert "Image content type error" not in error_message