Currently, I am in the process of developing Webdriver automation for a specific web application. As part of this process, I have created a test that seems to be functioning well most of the time but occasionally encounters an issue.
it('verifies presence of five items', async function(done) {
try {
await driver.wait(until.elementLocated(By.className('item-class')),5000);
const items = await driver.findElements(By.className('item-class'));
expect(items.length).toBe(5);
done();
}
catch(err) {
console.log(err)
}
}
The problem arises when the test fails with the following message:
Expected 0 to be 5.
Situations where there are zero items present on the page at the time of expectation seem perplexing based on my understanding. I anticipated that by using the initial code line to ensure the existence of these items, encountering a scenario where no items were found should not be possible during the subsequent expect() call.
This situation raises several questions:
1) What crucial detail or concept might I be overlooking that makes such an outcome feasible?
2) Is there potentially a more effective strategy or technique that could be utilized to delay execution until the expected number of items are visible on the screen?