diff --git a/lib/core/engine/command/wait.js b/lib/core/engine/command/wait.js index de5dd037f..2f89ed76e 100644 --- a/lib/core/engine/command/wait.js +++ b/lib/core/engine/command/wait.js @@ -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. @@ -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} 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. *