20
Jun

timeout in WebDriver

The timeouts() methods [driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);] are not implemented in some drivers and are very unreliable in general.

I use a separate thread for the timeouts (passing the url to access as the thread name):

Thread t = new Thread(new Runnable()
{
public void run()
{
driver.get(Thread.currentThread().getName());
}
}, url);
t.start();
try
{
t.join(YOUR_TIMEOUT_HERE_IN_MS);
}
catch (InterruptedException e)
{ // ignore
}
if (t.isAlive())
{ // Thread still alive, we need to abort
logger.warning(“Timeout on loading page ” + url);
t.interrupt();
}
This seems to work most of the time, however it might happen that the driver is really stuck and any subsequent call to driver will be blocked (I experience that with Chrome driver on Windows). Even something as innocuous as a driver.findElements() call could end up being blocked. Unfortunately I have no solutions for blocked drivers.