'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
Solution 1:[1]
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();
}
Solution 2:[2]
You may use this to assert if your td contains the text coming from formatedAccount as follows:
test ('test..',
async t => {
const field = Selector('td');
const text = field.textContent;
await t
.expect(text).contains(formatedAccount)
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ali Safari |