2 Excellent Synchronization Techniques in Selenium Webdriver

What is Synchronization & why it is needed?

if our application is taking time to load but our automation tool commands are running fast, this will result in error. .It is required so that our AUT and Testing Tool are running in sync with each other .For example  To make sure selenium/UFT waits for the application controls to load, so that tool can take an action on them we need synchronization. In simple words using waits, we are telling tool engine to wait for a certain amount of time before going to the next step.It's significance have further enhanced with dynamic websites using things like Angular JS and Ajax

Synchronization can be classified into two categories:

1. Unconditional Synchronization

  • Thread.Sleep()

2. Conditional Synchronization
  • Implicit Wait 
  • Explicit Wait

1. Unconditional Synchronization

Must read : Absolute path vs relative path

Specify  ONLY the timeout value WITHOUT any condition (like change in element attribute etc.). It makes the tool to forcefully  wait until that specific amount of time.This is used when we want Web Driver  to wait for the specified time, so that AUT completes its current operations.It is like pausing the script run for the given amount time.

Given script will pause for 2 seconds.
Thread.Sleep() is not considered as good coding practice, because it pauses the script without any condition and Web Driver  would wait even if the process for which wait was applied have been completed.

Advantage - Sometimes it is not possible to write a condition or check for a condition , like when we use third party systems like interfaces, We have to make the application to wait for specific amount of time by specifying the timeout value.
Disadvantage - Sometimes there is unnecessary waiting time , even when the application is ready to move forward with the execution.

                                                                                                      Next > Conditional Wait Synchronization