Tech Blog

Testing

Best Practices of Setting Timeouts in Selenium

By Birundha G1 min read
← Back to blog

What is timeouts in selenium?

If you are expecting any test cases to be completed within specified time, then we need to mention that specified period of time within the timeouts attribute.

Different Timeouts in selenium:

1. implicitlyWait()

2. setScriptTimeout()

3. pageLoadTimeout()

implicitlyWait()

Implicit wait is used to set a default wait time in the automation script to wait for an element visibility on the page.

Example:

Implicitly Wait for 10 seconds

WebDriver driver= new CromeDriver();
driver.get("https://suremdm.42gears.com/");
driver.manage().timeouts().implicityWait(10,TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@id='email']")).sendKeys("abc@gmail.com");

setScriptTimeout()

Set the amount of time to wait for an asynchronous script to complete execution, but if the process is not finished before the time limit, it is throwing an exception.

Example:

setScriptTimeout for 5 seconds

JavascriptExecutor js=(JavascriptExecutor)driver;
s.executeScript("alert('Have a nice day');");
driver.manage().timeouts().setScriptTimeout(5,TimeUnit.SECONDS);
js.executeAsyncScript("window.setTimeout(arguments[arguments.length-1], 500);");

pageLoadTimeout()

Set the amount of time to wait for page load to be complete or pageLoadTimeout is waiting for an application page load completely.

Example:

set the time of 10 seconds for page to complete the loading

WebDriver driver= new CromeDriver();
driver.manage().timeouts().pageLoadTimeout(10,TimeUnit.SECONDS);
driver.get.("https://suremdm.42gears.com/");

Selenium Timeouts must be included to create effective and comprehensive running test cases.

Keep reading

You may be interested in

Browse all articles →
Software Testing: Challenges and Solutions
February 8, 20244 min read

Software Testing: Challenges and Solutions

Introduction – Testing software is a crucial aspect of the development process. It makes sure that the product’s functionality works as expected, fulfills the user requirements, and makes sure it works without errors. In this blog, we will list down some of the most common challenges faced in software testing and conclude with how to […]

By Saboor ChandshahaRead More →
Streamlining Software Quality: The Power of Automating Black Box Testing
February 8, 20244 min read

Streamlining Software Quality: The Power of Automating Black Box Testing

Introduction :  In the dynamic realm of software development, ensuring the robustness and reliability of applications is of paramount importance. Black box testing, a technique that assesses software functionality without requiring knowledge of its internal code, plays a vital role in identifying potential defects. As the complexity of software systems continues to escalate, the manual […]

By Anthony Gilchrist G SRead More →
Implementing best practices for end-to-end testing in cloud migration
January 31, 20245 min read

Implementing best practices for end-to-end testing in cloud migration

Importance of End-to-End Testing Assume an organization’s core systems are now hosted on the cloud—a complex ecosystem linked by data threads. End-to-end testing is the foundation upon which the reliability and performance of this interconnected web is built. This rigorous testing technique makes it possible to detect vulnerabilities, optimize operations, and improve user experience. Active […]

By Rahul ChakravartiRead More →