lunes, 1 de junio de 2015

Using Explicit and Implicit waits

Web applications now want to appear as though they are desktop applications as more and more people move to hardware like tablets or netbooks which have very small hard drives. this is all done through AJAX to the page.

This means that when we are working with selenium WebDriver we need to have it synchronized with what is happening on the page. We don't want to use something like Thread.sleep() because that doesn't make our tests run as quickly as possible. We need to use one of the next two approaches: Implicit  or explicit waits.


Implicit wait:We can  tell selenium that we would like to wait for a certain amount of time before throwing an exception that it can not find the element on the page.We should note that implicit wait will be in place for the entire time the browser is open.This means that any search for elements on the page could take the time the implicit wait is set for.
 To make the code to wait an element to appear in DOM implicit wait timeout once set, is set for the lifetime of the WebDriver object instance.
driver.manage().timeouts().implicitlyWait(5,timeUnit.SECONDS)


Explicit wait:Unfortunately implicit waits do not fit situations and for some developers is not the right thing to do. Explicit waits is when know what we want to happen and the error needs to fit that situation. To wait for certain conditional to occur before moving forward ,this can be achieved with the combination to poll by every 500 milliseconds util it returns successfully.
(new WebDriverWait(driver,10))until(ExpectedConditions.elementToBeClickable(element));

For the other methods we need to import the followings
Import.org.openqa.selenium.support.ui.WebDriverWait;
import.org.openqa.seleniu.support.ui.ExpectedConditions;

Create a new class  in which we will have our explicit and explicit waits.






Create a new class where we will have our  page's locations

Create a new class for our test. 



No hay comentarios:

Publicar un comentario