I would like check if an element has a specific string it the class attribute.
The toHaveClass
assertion looks promising but does not seem to allow to check for one specific class string.
Assuming the following element <div class="a b">
, I would like to check for a
using await expect(myLocator).toHaveClass('a')
but this does not work because the api would expect class to be "a b".
Is there is simple way to exist an element to have one specific string in its class list?
You can use a Regex if you want to do a partial match, see: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-class