Introduction:
Contents
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 Webdriverwait selenium 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 Webdriverwait selenium until our application is ready before performing a certain action. There are several options that we can use to synchronize our test.
I would be discussing the important aspect of different wait types in selenium automation process. I have seen that there is a huge confusion in understanding different wait types and its significance. So this blog would exclusively explain what are the different wait types.
There are basically three wait types in selenium automation:
- Implicit Wait type.
- Explicit Wait type.
- Fluent Wait type.
Implicit Wait Type:
Implicit wait in selenium has borrowed the idea of ‘Implicit Wait’ type from Watir. Selenium webdriver wait for page to load this basically tells selenium to wait for a certain amount of time before throwing an exception that it cannot find the element of the page. We should note that the implicit wait will be in place fir the entire time the browser is open. This means that any search for elements on the page by the webdriver should take the time the implicit wait is for. If we do not provide selenium with this wait then Selenium would start throwing ElementNotFound exception because the time taken for selenium to interact with the corresponding element in the browser was not given. This is applicable for all the web elements in the browser. For example
from selenium import webdriver
class BrowserInteractions():
def test(self):
driver = webdriver.Firefox()
driver.get('https://google.com
driver.implicitly_wait(10)
Explicit Wait Type:
Explicit wait in selenium is more extendable in the means that you can set it up to wait for any specific condition. Usually we use the expected conditions selenium object to specify the condition to provide the corresponding explicit wait. For example
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC class BrowserInteractions(): def test(self): driver = webdriver.Chrome() driver.get('http://www.quora.com/Kevin-Rose element = WebDriverWait(driver, 2). until(EC.presence_of_element_located ((By.PARTIAL_LINK_TEXT, "Followers"))) element.click()
Fluent Wait Type:
Fluent wait in selenium is a part of the Explicit Wait type. Fluent Wait instance defines the maximum amount of time to wait for a condition as well the frequency with which to check the condition. For example
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import * import time class ExplicitWait(): def test(self): baseURL = "http://www.cleartrip.com/" bin_path = "/usr/local/bin/chromedriver" driver = webdriver.Chrome(executable_path=bin_path) driver.get(baseURL) driver.implicitly_wait(.5) driver.maximize_window() input_from = driver.find_element(By.ID,"FromTag input_from.send_keys("blr") input_to = driver.find_element(By.ID,"ToTag input_to.send_keys("ccu") input_depart_date = driver.find_element(By.ID,"DepartDate input_depart_date.send_keys("Sun, 4 Jun, 2017") input_depart_date.send_keys(Keys.ENTER) input_searchBtn = driver.find_element(By.ID,"SearchBtn input_searchBtn.click() wait = WebDriverWait(driver, 10, poll_frequency=1, ignored_exceptions=[NoSuchElementException, ElementNotVisibleException, ElementNotSelectableException]) element = wait.until(EC. element_to_be_clickable((By.ID,"1_1_MULTI element.click() time.sleep(2) driver.quit() ew = ExplicitWait() ew.test()
This selenium testing tutorial is a very important concept when we are performing automation using Selenium and I hope I was able to clear the difference between the three wait types.
Soumyajit is 5+ years experienced Software professional with his prime focus on automation technologies based on quality development and takes interest in the CI/CD processes. He provides help in developing the QA process in an organization with his skills in automation for the web platform. His focus is on improving the delivery process for an ongoing project and connects the dot to help out with a successful deployment. He has experience in working on analytics, e-commerce, and the ad-tech domain.
Besides being a professional he takes an immense interest in learning new skills and technologies. He is a research guide author/writer at Dzone and Web Code Geeks. He also maintains a blog platform of his own where he likes to keep up his technology junks.