Course Content
Selenium Python First Script
Selenium Python First Script
0/2
HTML Form elements
HTML Form elements
0/1
Handle HTML Frames
Handle HTML Frames
0/2
Handling Dropdown Lists
Handling Dropdown Lists
0/2
Selenium Action class
Selenium Action class
0/1
Selenium Python for Beginners [ 2024 ]
About Lesson

Selenium Test Synchronization

In automated testing, synchronization helps coordinate the execution of scripts, ensuring that the tests run smoothly and as intended. For example, the application may load a new page after clicking a button.

Synchronizing a test involves adjusting the time it takes for the web application to process the automation command, matching the speed at which the automation script sends the command to the application.

The test script should wait for the page to load and verify the target page. Without test synchronization, automation scripts may become flaky. A flaky test can report a failure even when the application works as expected.

Test Synchronization

Types of Waits

The different synchronization techniques that you can use in Selenium are as follows:

  • Hardcoded Waits ( time.sleep())
  • Implicit Wait
  • Explicit Wait

Types of Selenium Waits

Test synchronization improves the tests’ reliability and confidence in the automation suite.

The most common wait strategy is to place a static wait using the time. sleep() method. However, using a static wait in the automation code is not recommended because we generally do not know if the time allocated to wait is less or more.

time.sleep(5)

For example, the above code waits for 5 seconds in the code.
You cannot specify a lot of time to wait because that will delay the test, and if we provide less time, it may result in a flaky test. For example, the test waits 10 seconds, but the application takes more than 10 seconds to load, etc. Static waits are unreliable and not advisable in the code.

Join the conversation