We have already heard about thread.sleep and other explicit waits but there are few waits which are provided by WebDrivers too :
1) implicitlyWait : Specifies the amount of time the driver should wait when searching for an element if it is not immediately present. It works on DOM level. When searching for a single element, the driver should poll the page until the element has been found, or this timeout expires before throwing a NoSuchElementException. When searching for multiple elements, the driver should poll the page until at least one element has been found or this timeout has expired.
Increasing the implicit wait timeout should be used judiciously as it will have an adverse effect on test run time, especially when used with slower location strategies like XPath.
2) setScriptTimeout : Sets the amount of time to wait for a page load to complete before throwing an error. Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
3) pageLoadTimeout : Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
No comments:
Post a Comment