While researching Selenium Webdriver framework best practices on GitHub, I came across the following code snippet:
async function waitForVisible(driver, locator, retries = 3) {
try {
const element = await driver.findElement(locator);
await driver.wait(until.elementIsVisible(element), WAIT_TIME_OUT)
} catch (err) {
throw new Error(`Element "${locator.toString}" is not visible after maximum retries, error message: ${err.message}`)
}
await driver.sleep(WAIT_TIME_BEFORE_RETRY);
return waitForVisible(driver, locator, retries - 1)
}
Upon examining this function, it appears to be recursively calling itself indefinitely until an exception is eventually thrown. However, through testing, I observed that it actually does end without throwing an exception.
This raises the question of how exactly the "loop" terminates and under what circumstances. I am diligently trying to comprehend the inner workings of this code.