Roger Studner
Roger Studner

Reputation: 108

Testcafe how to get the count of something to use outside of an expect

test('Check on the individual devices stuff', async t => {
    const devices = monitoredDevicesSection.find('.card');
    console.log(devices);
    console.log(devices.count);
    console.log(await devices.count);
    await t.expect(devices.count).eql(10);
});

Alrighty -- using testcafe I'm trying to figure out how to get my hands on the count of something, outside of an expect.

In the above code, the test passes because there are in fact 10 things with class .card there.

BUT, I can't even assign a variable/console.log anything and get '10'

The above console.log (the last one) will always print 0.

I feel like I've tried all manners and orderings of awaits and what not.. and I simply can't get const actualCount = console.log(actualCount) to print 10.

Thoughts? I know I must be right on the edge of getting this right hah.

Upvotes: 2

Views: 2328

Answers (2)

Arturo Tapia
Arturo Tapia

Reputation: 21

I faced the same issue time ago (leave here the answer for google search):

function select(selector){
    return Selector(selector).with({boundTestRun:testController})
}

const devices= select('.card');
const devices_count = await devices.count

Upvotes: 0

BarretV
BarretV

Reputation: 1197

If you add an await I believe it should take a snapshot of the dom so that you can console.log the count. Hopefully that will work out for you

const devices = await monitoredDevicesSection.find('.card');

Upvotes: 3

Related Questions