Skip to content

Commit 6573aad

Browse files
committed
fix(assertions): accept pseudo in not_to_have_css
Fixes: #3244
1 parent f549909 commit 6573aad

5 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎playwright/_impl/_assertions.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,10 @@ async def not_to_have_css(
505505
name: str,
506506
value: Union[str, Pattern[str]],
507507
timeout: float = None,
508+
pseudo: Literal["after", "before"] = None,
508509
) -> None:
509510
__tracebackhide__ = True
510-
await self._not.to_have_css(name, value, timeout)
511+
await self._not.to_have_css(name, value, timeout, pseudo)
511512

512513
async def to_have_id(
513514
self,

‎playwright/async_api/_generated.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14112,6 +14112,7 @@ async def not_to_have_css(
1411214112
name: str,
1411314113
value: typing.Union[str, typing.Pattern[str]],
1411414114
*,
14115+
pseudo: typing.Optional[Literal["after", "before"]] = None,
1411514116
timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
1411614117
) -> None:
1411714118
"""LocatorAssertions.not_to_have_css
@@ -14124,13 +14125,15 @@ async def not_to_have_css(
1412414125
CSS property name.
1412514126
value : Union[Pattern[str], str]
1412614127
CSS property value.
14128+
pseudo : Union["after", "before", None]
14129+
Pseudo-element to read computed styles from.
1412714130
timeout : Union[float, None]
1412814131
Time to retry the assertion for in milliseconds. Defaults to `5000`.
1412914132
"""
1413014133
__tracebackhide__ = True
1413114134

1413214135
await self._impl_obj.not_to_have_css(
14133-
name=name, value=value, timeout=to_milliseconds(timeout)
14136+
name=name, value=value, pseudo=pseudo, timeout=to_milliseconds(timeout)
1413414137
)
1413514138

1413614139
async def not_to_have_id(

‎playwright/sync_api/_generated.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14184,6 +14184,7 @@ def not_to_have_css(
1418414184
name: str,
1418514185
value: typing.Union[str, typing.Pattern[str]],
1418614186
*,
14187+
pseudo: typing.Optional[Literal["after", "before"]] = None,
1418714188
timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
1418814189
) -> None:
1418914190
"""LocatorAssertions.not_to_have_css
@@ -14196,14 +14197,16 @@ def not_to_have_css(
1419614197
CSS property name.
1419714198
value : Union[Pattern[str], str]
1419814199
CSS property value.
14200+
pseudo : Union["after", "before", None]
14201+
Pseudo-element to read computed styles from.
1419914202
timeout : Union[float, None]
1420014203
Time to retry the assertion for in milliseconds. Defaults to `5000`.
1420114204
"""
1420214205
__tracebackhide__ = True
1420314206

1420414207
self._sync(
1420514208
self._impl_obj.not_to_have_css(
14206-
name=name, value=value, timeout=to_milliseconds(timeout)
14209+
name=name, value=value, pseudo=pseudo, timeout=to_milliseconds(timeout)
1420714210
)
1420814211
)
1420914212

‎tests/async/test_assertions.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@ async def test_assertions_locator_to_have_css(page: Page, server: Server) -> Non
198198
)
199199

200200

201+
async def test_assertions_locator_to_have_css_pseudo(page: Page) -> None:
202+
await page.set_content(
203+
"""
204+
<style>
205+
#node::before {
206+
color: rgb(255, 0, 0);
207+
content: "Text content";
208+
}
209+
</style>
210+
<div id=node></div>
211+
"""
212+
)
213+
locator = page.locator("#node")
214+
await expect(locator).to_have_css("color", "rgb(255, 0, 0)", pseudo="before")
215+
await expect(locator).not_to_have_css("color", "rgb(255, 0, 0)", timeout=100)
216+
await expect(locator).not_to_have_css(
217+
"color", "rgb(42, 42, 42)", pseudo="before", timeout=100
218+
)
219+
with pytest.raises(AssertionError):
220+
await expect(locator).not_to_have_css(
221+
"color", "rgb(255, 0, 0)", pseudo="before", timeout=100
222+
)
223+
224+
201225
async def test_assertions_locator_to_have_id(page: Page, server: Server) -> None:
202226
await page.goto(server.EMPTY_PAGE)
203227
await page.set_content("<div class=foobar id=kek>kek</div>")

‎tests/sync/test_assertions.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@ def test_assertions_locator_to_have_css(page: Page, server: Server) -> None:
181181
)
182182

183183

184+
def test_assertions_locator_to_have_css_pseudo(page: Page) -> None:
185+
page.set_content(
186+
"""
187+
<style>
188+
#node::before {
189+
color: rgb(255, 0, 0);
190+
content: "Text content";
191+
}
192+
</style>
193+
<div id=node></div>
194+
"""
195+
)
196+
locator = page.locator("#node")
197+
expect(locator).to_have_css("color", "rgb(255, 0, 0)", pseudo="before")
198+
expect(locator).not_to_have_css("color", "rgb(255, 0, 0)", timeout=100)
199+
expect(locator).not_to_have_css(
200+
"color", "rgb(42, 42, 42)", pseudo="before", timeout=100
201+
)
202+
with pytest.raises(AssertionError):
203+
expect(locator).not_to_have_css(
204+
"color", "rgb(255, 0, 0)", pseudo="before", timeout=100
205+
)
206+
207+
184208
def test_assertions_locator_to_have_id(page: Page, server: Server) -> None:
185209
page.goto(server.EMPTY_PAGE)
186210
page.set_content("<div class=foobar id=kek>kek</div>")

0 commit comments

Comments
 (0)