Synchronizing WebDriver

We can synchronize the web driver in two ways :

1. Explicit wait : For explicit wait we have to use thread.sleep().

Disadvantage in explicit wait

Each and every time when there is need to match speed of the application and speed of test execution we have to use thread.sleep().

For example : If the application needs to be synchronized for 10 times ( 10 times pages are getting loaded), we have to use thread.sleep() statement for 10 times.

  • sleep() will wait for the entire time that is specified even if the page is loaded or not.

Ex : If specified time is 60 seconds, but page loads within 10 seconds, the statement waits for another 50 seconds.

2. Implicit wait :

The command for implicit wait is :

driver.manage().timeout().implicitWait(arg1, arg2);

In arg1, specify the time that needs to be waited in number. Ex: 30, 40 , 60 …

In arg2, specify whether the arg1 should wait for seconds or minutes or days etc. ex: TimeUnit.SECONDS

If we use implicit wait, we need not use each and every time if the pages are getting loaded, rather use only once in the entire script. Always once in the entire script, use in the beginning of script.

The implicit wait will not wait for the entire time that is specified, rather it will only wait, until the entire page is laoded. As soon as page is loaded, it will execute next step. For example, if the specified time is 50 seconds and if the page gets loaded within 5 seconds, the implicit wait will not wait for another 45 seconds, rather it will come out of the wait loop and execute next step.

Add Comment