How can I get a text of one column of the table using testcafe and then i assert its eql to "something"

Viewed 762

I have a page with "search field" and "search button" and a table with 5 columns. I want to make an automation test with testcafe + javascript as following:

1: Type in "search field" - DONE

2: Click "search button" - DONE

3: Get the TEXT of all elements in the second column and assert it that its equal to "something"

I made it with Java + Selenium WebDriver. It was done with but I'm not that good with JavaScript and still cant investigate how to do it.

2 Answers

Maybe something like the following code help you:

const secondColumnElements = Selector('table tr td:nth-child(2n)');
const elementsCount = await secondColumnElements.count;
let text = '';

for (let i = 0; i < elementsCount; i++)
    text += await secondColumnElements.nth(i).textContent;

await t.expect(text).eql('something');

When i run the test the following error is shown:

errMsg: 'AssertionError: expected ' +
       "'Do[object Object]' to deeply " +
       "equal 'Do'"

Here is the code:

const secondColumnElements = Selector (Selector)
const elementsCount = await secondColumnElements.count;

let text = '';

for (let i = 0; i < elementsCount; i += 1) {
 text += secondColumnElements.nth(i).textContent;
}

await testController.expect(text).eql('Do');
});
Related