In my test case there is an element that should be checked if it contains any text and it’s not empty, and if it’s empty fail the test.
I’ve tried to use toHaveText
without a string like so:
await expect(myLocator).toHaveText();
but passing string/regex is mandatory.
How can I assert this kind of thing?
3
Answers
I've found a way using Regex "Dot" Metacharacter, which means Any character (except newline character):
You should try the following test :
You could use the following to check if the element has any text in it:
As found in the playwright documentation (
https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-be-empty):