|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import collections.abc |
16 | | -from typing import Any, List, Optional, Pattern, Sequence, Union |
| 16 | +from typing import Any, List, Literal, Optional, Pattern, Sequence, Union |
17 | 17 | from urllib.parse import urljoin |
18 | 18 |
|
19 | 19 | from playwright._impl._api_structures import ( |
|
26 | 26 | from playwright._impl._errors import Error |
27 | 27 | from playwright._impl._fetch import APIResponse |
28 | 28 | from playwright._impl._helper import is_textual_mime_type |
| 29 | +from playwright._impl._js_handle import parse_value |
29 | 30 | from playwright._impl._locator import Locator |
30 | 31 | from playwright._impl._page import Page |
31 | 32 | from playwright._impl._str_utils import escape_regex_flags |
@@ -71,7 +72,14 @@ async def _expect_impl( |
71 | 72 | del expect_options["useInnerText"] |
72 | 73 | result = await self._call_expect(expression, expect_options, title) |
73 | 74 | if result["matches"] == self._is_not: |
74 | | - actual = result.get("received") |
| 75 | + received = result.get("received") or {} |
| 76 | + if isinstance(received, dict): |
| 77 | + if "value" in received and received["value"] is not None: |
| 78 | + actual = parse_value(received["value"]) |
| 79 | + else: |
| 80 | + actual = received.get("ariaSnapshot") |
| 81 | + else: |
| 82 | + actual = received |
75 | 83 | if self._custom_message: |
76 | 84 | out_message = self._custom_message |
77 | 85 | if expected is not None: |
@@ -161,6 +169,24 @@ async def not_to_have_url( |
161 | 169 | __tracebackhide__ = True |
162 | 170 | await self._not.to_have_url(urlOrRegExp, timeout, ignoreCase) |
163 | 171 |
|
| 172 | + async def to_match_aria_snapshot( |
| 173 | + self, expected: str, timeout: float = None |
| 174 | + ) -> None: |
| 175 | + __tracebackhide__ = True |
| 176 | + await self._expect_impl( |
| 177 | + "to.match.aria", |
| 178 | + FrameExpectOptions(expectedValue=expected, timeout=timeout), |
| 179 | + expected, |
| 180 | + "Page expected to match Aria snapshot", |
| 181 | + 'Expect "to_match_aria_snapshot"', |
| 182 | + ) |
| 183 | + |
| 184 | + async def not_to_match_aria_snapshot( |
| 185 | + self, expected: str, timeout: float = None |
| 186 | + ) -> None: |
| 187 | + __tracebackhide__ = True |
| 188 | + await self._not.to_match_aria_snapshot(expected, timeout) |
| 189 | + |
164 | 190 |
|
165 | 191 | class LocatorAssertions(AssertionsBase): |
166 | 192 | def __init__( |
@@ -400,13 +426,17 @@ async def to_have_css( |
400 | 426 | name: str, |
401 | 427 | value: Union[str, Pattern[str]], |
402 | 428 | timeout: float = None, |
| 429 | + pseudo: Literal["after", "before"] = None, |
403 | 430 | ) -> None: |
404 | 431 | __tracebackhide__ = True |
405 | 432 | expected_text = to_expected_text_values([value]) |
406 | 433 | await self._expect_impl( |
407 | 434 | "to.have.css", |
408 | 435 | FrameExpectOptions( |
409 | | - expressionArg=name, expectedText=expected_text, timeout=timeout |
| 436 | + expressionArg=name, |
| 437 | + expectedText=expected_text, |
| 438 | + timeout=timeout, |
| 439 | + pseudo=pseudo, |
410 | 440 | ), |
411 | 441 | value, |
412 | 442 | "Locator expected to have CSS", |
|
0 commit comments