Synchronization in Test Automation

Posted by Albert Gareev on Oct 10, 2007 | Categories: Robustness

Synchronization in Test Automation

What’s it about?

As in regular, human-to-human conversation, it is important not to interrupt each other, and wait till a talker finishes a message, in human-to-program, and in program-to-program interaction, giving time is important.

In conversation, we usually recognize end of a message by a pause in speech. In interaction with a program, we can rely on usability-designed behavior (if a program has it, off course):

  • progress bars 
  • status messages
  • enabling/disabling of GUI controls
  • pop-up dialogs

Why it’s important for Test Automation?

Unlike people, a program can never “go back”. So, if by the moment when testing script was going to perform a GUI operation on a control, it was not available (did not appear yet, was disabled, was not populated with data, etc.), the script will report the operation as failed. (In worst case scenario, the script will stop, and the entire execution flow will be broken).

To prevent such type of false positive errors (i.e. there was no test failure, but script reported as it was), special programming approach has to be taken: synchronization by event.

How to define an event?

First of all, try to pick a “natural” (intended for a human user) event. That could be a status message, GUI object, or state of a window or GUI control.

If “natural” events are not available, then, first, a program has usability defects, second, you will have to find a context-specific solution.

Commercial test automation tools, like WinRunner, QTP, or TestComplete have a built-in support for GUI events and synchronization points.

How to code a synchronization point?

Basically, it’s a cycle that ends in to cases: synchronization event occured or timeout reached. Having exit by timeout is important to evade infinite loops.

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.