Aric2148
Aric2148

Reputation: 1

How to verify text does not exist on a web page with assertions

I'm new to Test Cafe Studio and I'm trying to figure out how to verify text is not present on a web page. I would like the test to fail if the text is present. Any help would be appreciated.

Upvotes: 0

Views: 276

Answers (1)

pavelsaman
pavelsaman

Reputation: 8322

Typically, you want to assert a text of some element:

const elText = await Selector('#my-element').textContent;
await t
    .expect(elText).notContains('some text');

If you want to check the whole page, you might do this:

const elText = await Selector('html').textContent;
await t
    .expect(elText).notContains('some text');

But I think it's better to avoid it and rather structure your tests in a way that:

  • you check for presence, not absence
  • you check concrete things, not the whole page

Upvotes: 3

Related Questions