@@ -126,12 +126,28 @@ def test_assertions_locator_to_have_class(page: Page, server: Server) -> None:
126126
127127def test_assertions_locator_to_contain_class (page : Page , server : Server ) -> None :
128128 page .goto (server .EMPTY_PAGE )
129- page .set_content ("<div class='foo bar another foobar'>kek</div>" )
130- expect (page .locator ("div.foobar" )).to_contain_class ("foobar" )
131- expect (page .locator ("div.foobar" )).to_contain_class (["another foobar" ])
132- expect (page .locator ("div.foobar" )).not_to_contain_class ("kekstar" , timeout = 100 )
133- with pytest .raises (AssertionError ):
134- expect (page .locator ("div.foobar" )).to_contain_class ("oh-no" , timeout = 100 )
129+ page .set_content ("<div class='foo bar baz'></div>" )
130+ locator = page .locator ("div" )
131+ expect (locator ).to_contain_class ("" )
132+ expect (locator ).to_contain_class ("bar" )
133+ expect (locator ).to_contain_class ("baz bar" )
134+ expect (locator ).to_contain_class (" bar foo " )
135+ expect (locator ).not_to_contain_class (
136+ " baz not-matching "
137+ ) # Strip whitespace and match individual classes
138+ with pytest .raises (AssertionError ) as excinfo :
139+ expect (locator ).to_contain_class ("does-not-exist" , timeout = 100 )
140+
141+ assert excinfo .match ("Locator expected to contain class 'does-not-exist'" )
142+ assert excinfo .match ("Actual value: foo bar baz" )
143+ assert excinfo .match ("LocatorAssertions.to_contain_class with timeout 100ms" )
144+
145+ page .set_content (
146+ '<div class="foo"></div><div class="hello bar"></div><div class="baz"></div>'
147+ )
148+ expect (locator ).to_contain_class (["foo" , "hello" , "baz" ])
149+ expect (locator ).not_to_contain_class (["not-there" , "hello" , "baz" ])
150+ expect (locator ).not_to_contain_class (["foo" , "hello" ])
135151
136152
137153def test_assertions_locator_to_have_count (page : Page , server : Server ) -> None :
0 commit comments