Jakub Sip
Jakub Sip

Reputation: 195

How to check if text exists in Testcafe

I would like to check if '64' exists on the page which I have created.

const x = Selector('.FilterCockpit--header--count').withText('64');

The following test fails.

test('x', async t => {
    await t
    .expect((x).exists).ok()
    });

HTML code:

<div class="FilterCockpit--header--results">
          <span class="FilterCockpit--header--count">
              64
         </span>
         Results
 </div>

What I am doing wrong? Thank you in advance for your help.

Upvotes: 3

Views: 4636

Answers (1)

Alex Skorkin
Alex Skorkin

Reputation: 4274

I've executed your test case with the latest TestCafe of version 1.1.4 and it is passed:

enter image description here

Here are my complete test case and a test file based on your code snippets:

import { Selector} from 'testcafe';

fixture('fixture')
    .page('file:///Temp/56074194.html');

const x = Selector('.FilterCockpit--header--count').withText('64');

test('x', async t => {

    await t
        .expect((x).exists).ok()
});

56074194.html 

<div class="FilterCockpit--header--results">
          <span class="FilterCockpit--header--count">
              64
         </span>
         Results
 </div>

Perhaps, there are some circumstances that may break the test execution. If there are any additional steps I need to perform, please let me know.

See also: Check if an Element Exists

Upvotes: 5

Related Questions