Selenium WebDriver: - Synchronizing a Test Using Waits
One of the Important Factor in test automation for a complex web application is to ensure that the flow of the test cases should be in synchronization with the application under test (AUT).
When tests are run, the application may not always respond with the same speed. For example, it might take a few seconds for a progress bar to reach 100 percent, a status message to appear, a button to become enabled, and a window or pop-up message to open. We can handle these anticipated timing problems by synchronizing our test to ensure that Selenium WebDriver waits until our application is ready before performing a certain action. There are several options that we can use to synchronize our test.
Synchronizing a test with an implicit wait
When an implicit wait is implemented it tells WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0.Once set the implicit wait is set for the life of the WebDriver object's instance. However, an implicit wait may slow down our tests when an application responds normally, as it will wait for each element to appear in the DOM and increase the overall execution time.
driver.manage().timeouts().implicitlyWait(Time period, TimeUnit.SECONDS);
Time period: Here time value is given as input. How many seconds the driver has to wait.
TimeUnit.SECONDS: Time period is measured as second here. You can use other time unit like day, microseconds, nanoseconds etc.