Tuesday, January 29, 2013

WebDriver waits


Web application automation is depends on so many factors. Browser, network speed ...etc. We should write unquie code for running in all environments. For achieveing that we need to wait for WebElements before performing any operation on that.

Here we will see some built-in waits in WebDriver.

implicitlyWait

1WebDriver driver = new FirefoxDriver();
2driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
3driver.get("http://www.google.co.in");
4WebElement myElement = driver.findElement(By.id("someId"));
Implicit waits are basically your way of telling WebDriver the latency that you want to see if specified web element is not present that WebDriver looking for. (Click here for more information). This will be useful when certain elements on the webpage will not be available immediately and needs some time to load.

pageLoadTimeout

1driver.manage().timeouts().pageLoadTimeout(30, SECONDS);
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.

setScriptTimeout

1driver.manage().timeouts().setScriptTimeout(30,SECONDS);

Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.


Regards,
SantoshSarma

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.