Skip to content

Commit 174d624

Browse files
authored
chore: add missing sync assertions (microsoft#1047)
1 parent 590fa91 commit 174d624

File tree

9 files changed

+341
-36
lines changed

9 files changed

+341
-36
lines changed

README.md

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

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->98.0.4695.0<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->98.0.4714.0<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> ||||
99
| Firefox <!-- GEN:firefox-version -->94.0.1<!-- GEN:stop --> ||||
1010

playwright/_impl/_assertions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AssertionsBase:
2525
def __init__(self, locator: Locator, is_not: bool = False) -> None:
2626
self._actual_locator = locator
2727
self._loop = locator._loop
28+
self._dispatcher_fiber = locator._dispatcher_fiber
2829
self._is_not = is_not
2930

3031
async def _expect_impl(
@@ -114,7 +115,7 @@ def _not(self) -> "LocatorAssertions":
114115

115116
async def to_contain_text(
116117
self,
117-
expected: Union[List[Pattern], List[str], Pattern, str],
118+
expected: Union[List[Union[Pattern, str]], Pattern, str],
118119
use_inner_text: bool = None,
119120
timeout: float = None,
120121
) -> None:
@@ -150,7 +151,7 @@ async def to_contain_text(
150151

151152
async def not_to_contain_text(
152153
self,
153-
expected: Union[List[Pattern], List[str], Pattern, str],
154+
expected: Union[List[Union[Pattern, str]], Pattern, str],
154155
use_inner_text: bool = None,
155156
timeout: float = None,
156157
) -> None:
@@ -185,7 +186,7 @@ async def not_to_have_attribute(
185186

186187
async def to_have_class(
187188
self,
188-
expected: Union[List[Pattern], List[str], Pattern, str],
189+
expected: Union[List[Union[Pattern, str]], Pattern, str],
189190
timeout: float = None,
190191
) -> None:
191192
__tracebackhide__ = True
@@ -208,7 +209,7 @@ async def to_have_class(
208209

209210
async def not_to_have_class(
210211
self,
211-
expected: Union[List[Pattern], List[str], Pattern, str],
212+
expected: Union[List[Union[Pattern, str]], Pattern, str],
212213
timeout: float = None,
213214
) -> None:
214215
__tracebackhide__ = True
@@ -332,7 +333,7 @@ async def not_to_have_value(
332333

333334
async def to_have_text(
334335
self,
335-
expected: Union[List[Pattern], List[str], Pattern, str],
336+
expected: Union[List[Union[Pattern, str]], Pattern, str],
336337
use_inner_text: bool = None,
337338
timeout: float = None,
338339
) -> None:
@@ -368,7 +369,7 @@ async def to_have_text(
368369

369370
async def not_to_have_text(
370371
self,
371-
expected: Union[List[Pattern], List[str], Pattern, str],
372+
expected: Union[List[Union[Pattern, str]], Pattern, str],
372373
use_inner_text: bool = None,
373374
timeout: float = None,
374375
) -> None:

playwright/async_api/_generated.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14537,7 +14537,7 @@ class LocatorAssertions(AsyncBase):
1453714537
async def to_contain_text(
1453814538
self,
1453914539
expected: typing.Union[
14540-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14540+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1454114541
],
1454214542
*,
1454314543
use_inner_text: bool = None,
@@ -14552,7 +14552,7 @@ async def to_contain_text(
1455214552

1455314553
Parameters
1455414554
----------
14555-
expected : Union[List[Pattern], List[str], Pattern, str]
14555+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1455614556
Expected substring or RegExp or a list of those.
1455714557
use_inner_text : Union[bool, NoneType]
1455814558
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
@@ -14573,7 +14573,7 @@ async def to_contain_text(
1457314573
async def not_to_contain_text(
1457414574
self,
1457514575
expected: typing.Union[
14576-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14576+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1457714577
],
1457814578
*,
1457914579
use_inner_text: bool = None,
@@ -14585,7 +14585,7 @@ async def not_to_contain_text(
1458514585

1458614586
Parameters
1458714587
----------
14588-
expected : Union[List[Pattern], List[str], Pattern, str]
14588+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1458914589
Expected substring or RegExp or a list of those.
1459014590
use_inner_text : Union[bool, NoneType]
1459114591
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
@@ -14668,7 +14668,7 @@ async def not_to_have_attribute(
1466814668
async def to_have_class(
1466914669
self,
1467014670
expected: typing.Union[
14671-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14671+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1467214672
],
1467314673
*,
1467414674
timeout: float = None
@@ -14681,7 +14681,7 @@ async def to_have_class(
1468114681

1468214682
Parameters
1468314683
----------
14684-
expected : Union[List[Pattern], List[str], Pattern, str]
14684+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1468514685
Expected class or RegExp or a list of those.
1468614686
timeout : Union[float, NoneType]
1468714687
Time to retry the assertion for.
@@ -14698,7 +14698,7 @@ async def to_have_class(
1469814698
async def not_to_have_class(
1469914699
self,
1470014700
expected: typing.Union[
14701-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14701+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1470214702
],
1470314703
*,
1470414704
timeout: float = None
@@ -14709,7 +14709,7 @@ async def not_to_have_class(
1470914709

1471014710
Parameters
1471114711
----------
14712-
expected : Union[List[Pattern], List[str], Pattern, str]
14712+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1471314713
Expected class or RegExp or a list of those.
1471414714
timeout : Union[float, NoneType]
1471514715
Time to retry the assertion for.
@@ -14974,7 +14974,7 @@ async def not_to_have_value(
1497414974
async def to_have_text(
1497514975
self,
1497614976
expected: typing.Union[
14977-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14977+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1497814978
],
1497914979
*,
1498014980
use_inner_text: bool = None,
@@ -14988,7 +14988,7 @@ async def to_have_text(
1498814988

1498914989
Parameters
1499014990
----------
14991-
expected : Union[List[Pattern], List[str], Pattern, str]
14991+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1499214992
Expected substring or RegExp or a list of those.
1499314993
use_inner_text : Union[bool, NoneType]
1499414994
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
@@ -15009,7 +15009,7 @@ async def to_have_text(
1500915009
async def not_to_have_text(
1501015010
self,
1501115011
expected: typing.Union[
15012-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
15012+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1501315013
],
1501415014
*,
1501515015
use_inner_text: bool = None,
@@ -15021,7 +15021,7 @@ async def not_to_have_text(
1502115021

1502215022
Parameters
1502315023
----------
15024-
expected : Union[List[Pattern], List[str], Pattern, str]
15024+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1502515025
Expected substring or RegExp or a list of those.
1502615026
use_inner_text : Union[bool, NoneType]
1502715027
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.

playwright/sync_api/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
web automation that is ever-green, capable, reliable and fast.
1919
"""
2020

21+
from typing import Union, overload
22+
2123
import playwright._impl._api_structures
2224
import playwright._impl._api_types
2325
import playwright.sync_api._generated
26+
from playwright._impl._assertions import LocatorAssertions as LocatorAssertionsImpl
27+
from playwright._impl._assertions import PageAssertions as PageAssertionsImpl
2428
from playwright.sync_api._context_manager import PlaywrightContextManager
2529
from playwright.sync_api._generated import (
2630
Accessibility,
@@ -40,8 +44,10 @@
4044
JSHandle,
4145
Keyboard,
4246
Locator,
47+
LocatorAssertions,
4348
Mouse,
4449
Page,
50+
PageAssertions,
4551
Playwright,
4652
Request,
4753
Response,
@@ -76,7 +82,28 @@ def sync_playwright() -> PlaywrightContextManager:
7682
return PlaywrightContextManager()
7783

7884

85+
@overload
86+
def expect(page_or_locator: Page) -> PageAssertions:
87+
...
88+
89+
90+
@overload
91+
def expect(page_or_locator: Locator) -> LocatorAssertions:
92+
...
93+
94+
95+
def expect(
96+
page_or_locator: Union[Page, Locator]
97+
) -> Union[PageAssertions, LocatorAssertions]:
98+
if isinstance(page_or_locator, Page):
99+
return PageAssertions(PageAssertionsImpl(page_or_locator._impl_obj))
100+
elif isinstance(page_or_locator, Locator):
101+
return LocatorAssertions(LocatorAssertionsImpl(page_or_locator._impl_obj))
102+
raise ValueError(f"Unsupported type: {type(page_or_locator)}")
103+
104+
79105
__all__ = [
106+
"expect",
80107
"Accessibility",
81108
"APIRequest",
82109
"APIRequestContext",

playwright/sync_api/_generated.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14260,7 +14260,7 @@ class LocatorAssertions(SyncBase):
1426014260
def to_contain_text(
1426114261
self,
1426214262
expected: typing.Union[
14263-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14263+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1426414264
],
1426514265
*,
1426614266
use_inner_text: bool = None,
@@ -14275,7 +14275,7 @@ def to_contain_text(
1427514275

1427614276
Parameters
1427714277
----------
14278-
expected : Union[List[Pattern], List[str], Pattern, str]
14278+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1427914279
Expected substring or RegExp or a list of those.
1428014280
use_inner_text : Union[bool, NoneType]
1428114281
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
@@ -14296,7 +14296,7 @@ def to_contain_text(
1429614296
def not_to_contain_text(
1429714297
self,
1429814298
expected: typing.Union[
14299-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14299+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1430014300
],
1430114301
*,
1430214302
use_inner_text: bool = None,
@@ -14308,7 +14308,7 @@ def not_to_contain_text(
1430814308

1430914309
Parameters
1431014310
----------
14311-
expected : Union[List[Pattern], List[str], Pattern, str]
14311+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1431214312
Expected substring or RegExp or a list of those.
1431314313
use_inner_text : Union[bool, NoneType]
1431414314
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
@@ -14391,7 +14391,7 @@ def not_to_have_attribute(
1439114391
def to_have_class(
1439214392
self,
1439314393
expected: typing.Union[
14394-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14394+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1439514395
],
1439614396
*,
1439714397
timeout: float = None
@@ -14404,7 +14404,7 @@ def to_have_class(
1440414404

1440514405
Parameters
1440614406
----------
14407-
expected : Union[List[Pattern], List[str], Pattern, str]
14407+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1440814408
Expected class or RegExp or a list of those.
1440914409
timeout : Union[float, NoneType]
1441014410
Time to retry the assertion for.
@@ -14421,7 +14421,7 @@ def to_have_class(
1442114421
def not_to_have_class(
1442214422
self,
1442314423
expected: typing.Union[
14424-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14424+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1442514425
],
1442614426
*,
1442714427
timeout: float = None
@@ -14432,7 +14432,7 @@ def not_to_have_class(
1443214432

1443314433
Parameters
1443414434
----------
14435-
expected : Union[List[Pattern], List[str], Pattern, str]
14435+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1443614436
Expected class or RegExp or a list of those.
1443714437
timeout : Union[float, NoneType]
1443814438
Time to retry the assertion for.
@@ -14697,7 +14697,7 @@ def not_to_have_value(
1469714697
def to_have_text(
1469814698
self,
1469914699
expected: typing.Union[
14700-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14700+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1470114701
],
1470214702
*,
1470314703
use_inner_text: bool = None,
@@ -14711,7 +14711,7 @@ def to_have_text(
1471114711

1471214712
Parameters
1471314713
----------
14714-
expected : Union[List[Pattern], List[str], Pattern, str]
14714+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1471514715
Expected substring or RegExp or a list of those.
1471614716
use_inner_text : Union[bool, NoneType]
1471714717
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
@@ -14732,7 +14732,7 @@ def to_have_text(
1473214732
def not_to_have_text(
1473314733
self,
1473414734
expected: typing.Union[
14735-
typing.List[typing.Pattern], typing.List[str], typing.Pattern, str
14735+
typing.List[typing.Union[typing.Pattern, str]], typing.Pattern, str
1473614736
],
1473714737
*,
1473814738
use_inner_text: bool = None,
@@ -14744,7 +14744,7 @@ def not_to_have_text(
1474414744

1474514745
Parameters
1474614746
----------
14747-
expected : Union[List[Pattern], List[str], Pattern, str]
14747+
expected : Union[List[Union[Pattern, str]], Pattern, str]
1474814748
Expected substring or RegExp or a list of those.
1474914749
use_inner_text : Union[bool, NoneType]
1475014750
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
InWheel = None
3131
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand
3232

33-
driver_version = "1.18.0-alpha-nov-18-2021"
33+
driver_version = "1.18.0-alpha-1637602750000"
3434

3535

3636
def extractall(zip: zipfile.ZipFile, path: str) -> None:

tests/async/test_accessibility.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ async def test_accessibility_should_work_an_input(page):
374374
}
375375

376376

377-
async def test_accessibility_should_work_on_a_menu(page, is_webkit):
377+
async def test_accessibility_should_work_on_a_menu(
378+
page, is_webkit, is_chromium, browser_channel
379+
):
378380
await page.set_content(
379381
"""
380382
<div role="menu" title="My Menu">
@@ -395,7 +397,7 @@ async def test_accessibility_should_work_on_a_menu(page, is_webkit):
395397
{"role": "menuitem", "name": "Third Item"},
396398
],
397399
}
398-
if is_webkit:
400+
if is_webkit or (is_chromium and not browser_channel):
399401
golden["orientation"] = "vertical"
400402
assert await page.accessibility.snapshot(root=menu) == golden
401403

tests/sync/test_accessibility.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ def test_accessibility_should_work_an_input(page: Page) -> None:
388388
}
389389

390390

391-
def test_accessibility_should_work_on_a_menu(page: Page, is_webkit: bool) -> None:
391+
def test_accessibility_should_work_on_a_menu(
392+
page: Page, is_webkit: bool, is_chromium: str, browser_channel: str
393+
) -> None:
392394
page.set_content(
393395
"""
394396
<div role="menu" title="My Menu">
@@ -409,7 +411,7 @@ def test_accessibility_should_work_on_a_menu(page: Page, is_webkit: bool) -> Non
409411
{"role": "menuitem", "name": "Third Item"},
410412
],
411413
}
412-
if is_webkit:
414+
if is_webkit or (is_chromium and not browser_channel):
413415
golden["orientation"] = "vertical"
414416
assert page.accessibility.snapshot(root=menu) == golden
415417

0 commit comments

Comments
 (0)