I need assistance with writing a Cucumber.js test that can effectively test the search form on my website. Currently, I am facing an issue where the subsequent steps run before the results page fully loads after entering a search term using Selenium Webdriver.
How can I ensure that the following steps only execute after the results page has completely loaded?
Below is a snippet of my code:
const { When, Then, AfterAll, Given } = require('@cucumber/cucumber');
const assert = require('assert');
const { Builder, By, until, Key } = require('selenium-webdriver');
const driver = new Builder()
.forBrowser('firefox')
.build();
Given('I am on the search page', async function () {
driver.wait(until.elementLocated(By.tagName('h1')));
await driver.get('https://www.awebsite.com/search');
});
When('I enter the term Honda', async function() {
await driver.findElement(By.className('search-input')).sendKeys('Honda', Key.RETURN);
});
Then('the search should return results', async function() {
let results = await driver.findElement(By.className("search-container_results"));
let count = await driver.findElement(By.className("search-results_count")).getText();
assert.equal(count, "5 results");
});
AfterAll(async function(){
await driver.quit();
});