We are working in legacy code and have a problem with flaky tests.
I’d like to increase the default timeout, but the driver.findElement is used in a lot of places – overriding each call to use WebDriverWait would be a big task.
I found a recommendation to use implicit waits, which looked ideal as it only needed to be set once:
getDriver().manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
I added this to the initialisation code block. Unfortunately, when I run one test case (50 tests) my performance bombs – increasing from ~30 seconds to 600 seconds.
I don’t understand why the performace has got so much worse – I thought it would only have taken the maximum time if the elements weren’t present (the tests passed). I thought this call would poll for the condition. But I also can’t see where to set the poll interval… It does mention in the documentation that it should be used judiciously, but this is completely unusable!
Are we on the right track with using implicitlyWait()? Is there another way to toughen up our tests?
UPDATE
On investigation, it appears that it is using implicitlyWait() and driver.getElements() that is slowing us down – if i nullify the implicitwait then reapply it straight after the call, then the tests run much faster. We use getElements ins over 400 places (!) – any recommendations on how to proceed?
We weren’t able to track down why this was happening with implicitlyWait. In the interests of making our build reliable, we wrote overrode getElement with our own polling mechanism, with a fairly low polling interval (100ms).
This has improved the accuracy of our tests, without affecting the build duration.