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.
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');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.