Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert if there exist a td DOM with a specific text in testcafe

I just started using testcafe, so far I found the documentation helpful to do my test and automate my E2E.

I want to assert if a value exists in a td like this:

async checkBankAccount(accountNumber, currencyCode){
         const formatedAccount = formatBankAccount(accountNumber, currencyCode);
         console.log(formatedAccount);
         await t
         .expect(Selector('td').withText(formatedAccount).innerText).eql(formatBankAccount);
     }

I am having the following error:

An assertion method is not specified.

I want to assert if it exists a td in my HTML that contains the text from formatedAccount.

Thanks

like image 983
Patrick Vibild Avatar asked Jan 23 '26 20:01

Patrick Vibild


1 Answers

 Use the exists property to check if an element is available.

async checkBankAccount(accountNumber, currencyCode){
    const formatedAccount = formatBankAccount(accountNumber, currencyCode);
    console.log(formatedAccount);

    await t
         .expect(Selector('td').withText(formatedAccount).exists).ok();
}
like image 128
mlosev Avatar answered Jan 25 '26 10:01

mlosev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!