|
14 | 14 |
|
15 | 15 | import collections.abc |
16 | 16 | from contextlib import contextmanager |
17 | | -from typing import Any, Iterator, List, Optional, Pattern, Sequence, Union |
| 17 | +from typing import Any, Iterator, List, Literal, Optional, Pattern, Sequence, Union |
18 | 18 | from urllib.parse import urljoin |
19 | 19 |
|
20 | 20 | from playwright._impl._api_structures import ( |
|
27 | 27 | from playwright._impl._errors import Error |
28 | 28 | from playwright._impl._fetch import APIResponse |
29 | 29 | from playwright._impl._helper import is_textual_mime_type |
| 30 | +from playwright._impl._js_handle import parse_value |
30 | 31 | from playwright._impl._locator import Locator |
31 | 32 | from playwright._impl._page import Page |
32 | 33 | from playwright._impl._str_utils import escape_regex_flags |
@@ -101,7 +102,14 @@ async def _expect_impl( |
101 | 102 | del expect_options["useInnerText"] |
102 | 103 | result = await self._call_expect(expression, expect_options, title) |
103 | 104 | if result["matches"] == self._is_not: |
104 | | - actual = result.get("received") |
| 105 | + received = result.get("received") or {} |
| 106 | + if isinstance(received, dict): |
| 107 | + if "value" in received and received["value"] is not None: |
| 108 | + actual = parse_value(received["value"]) |
| 109 | + else: |
| 110 | + actual = received.get("ariaSnapshot") |
| 111 | + else: |
| 112 | + actual = received |
105 | 113 | if self._custom_message: |
106 | 114 | out_message = self._custom_message |
107 | 115 | if expected is not None: |
@@ -199,6 +207,24 @@ async def not_to_have_url( |
199 | 207 | __tracebackhide__ = True |
200 | 208 | await self._not.to_have_url(urlOrRegExp, timeout, ignoreCase) |
201 | 209 |
|
| 210 | + async def to_match_aria_snapshot( |
| 211 | + self, expected: str, timeout: float = None |
| 212 | + ) -> None: |
| 213 | + __tracebackhide__ = True |
| 214 | + await self._expect_impl( |
| 215 | + "to.match.aria", |
| 216 | + FrameExpectOptions(expectedValue=expected, timeout=timeout), |
| 217 | + expected, |
| 218 | + "Page expected to match Aria snapshot", |
| 219 | + 'Expect "to_match_aria_snapshot"', |
| 220 | + ) |
| 221 | + |
| 222 | + async def not_to_match_aria_snapshot( |
| 223 | + self, expected: str, timeout: float = None |
| 224 | + ) -> None: |
| 225 | + __tracebackhide__ = True |
| 226 | + await self._not.to_match_aria_snapshot(expected, timeout) |
| 227 | + |
202 | 228 |
|
203 | 229 | class LocatorAssertions(AssertionsBase): |
204 | 230 | def __init__( |
@@ -443,13 +469,17 @@ async def to_have_css( |
443 | 469 | name: str, |
444 | 470 | value: Union[str, Pattern[str]], |
445 | 471 | timeout: float = None, |
| 472 | + pseudo: Literal["after", "before"] = None, |
446 | 473 | ) -> None: |
447 | 474 | __tracebackhide__ = True |
448 | 475 | expected_text = to_expected_text_values([value]) |
449 | 476 | await self._expect_impl( |
450 | 477 | "to.have.css", |
451 | 478 | FrameExpectOptions( |
452 | | - expressionArg=name, expectedText=expected_text, timeout=timeout |
| 479 | + expressionArg=name, |
| 480 | + expectedText=expected_text, |
| 481 | + timeout=timeout, |
| 482 | + pseudo=pseudo, |
453 | 483 | ), |
454 | 484 | value, |
455 | 485 | "Locator expected to have CSS", |
|
0 commit comments