Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wait by id and visible #2137

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/core/engine/command/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Wait {
}

/**
* Waits for an element with a specific ID to appear within a maximum time.
* Waits for an element with a specific ID to be located within a maximum time.
*
* @async
* @param {string} id - The ID of the element to wait for.
Expand All @@ -46,6 +46,30 @@ export class Wait {
}
}

/**
* Waits for an element with a specific ID to be located and visible within a maximum time.
*
* @async
* @param {string} id - The ID of the element to wait for.
* @param {number} maxTime - Maximum time to wait in milliseconds.
* @returns {Promise<void>} A promise that resolves when the element is found or the time times out.
* @throws {Error} Throws an error if the element is not found within the specified time.
*/
async byIdAndVisible(id, maxTime) {
const driver = this.browser.getDriver();
await this.byId(id, maxTime);
try {
await driver.wait(
webdriver.until.elementIsVisible(webdriver.By.id(id)),
maxTime
);
} catch (error) {
log.error('Element by id %s was not visible in %s ms', id, maxTime);
log.verbose(error);
throw new Error(`Element by id ${id} was not located in ${maxTime} ms`);
}
}

/**
* Waits for an element located by XPath to appear within a maximum time.
*
Expand Down
Loading