How Does Silk4NET Synchronize Tests?

Many unexpected test failures are related to synchronization issues. Weak synchronization during test replay might generate false negative results, making it difficult to detect actual application problems. Synchronization errors are timing issues that heavily depend on the test environment, making these errors difficult to reproduce and solve. For example, a synchronization error that occurs in a specific test environment might never be reproduced in the development environment. Weak synchronization is one of the most common reasons for an automation project to get unmanageable with a growing set of automated tests.

Silk4NET provides automated test synchronization for all supported technologies, enabling you to build robust and manageable test sets. During the replay of a test, Silk4NET ensures that the test always waits until the AUT is ready to perform the next action. For a verification step in a test, Silk4NET ensures that any preceding actions in the test are completed before performing the verification.

To adapt your tests to the specific behavior of your AUT, you can change the values of the following synchronization timeouts:
Synchronization timeout (OPT_SYNC_TIMEOUT)
The maximum time in milliseconds that Silk4NET waits for the AUT to become ready during playback. The default value is 300000 milliseconds.
Object resolve timeout (OBJ_WAIT_RESOLVE_OBJDEF)
The maximum time in milliseconds that the Find method searches for an object. The default value is 5000 milliseconds.
Note: To be able to successfully run tests under load or on slow systems, for example a virtual machine accessed through a slow connection, Silk4NET occasionally increases the internal timeout, for example while the AUT is starting and when a dialog or window appears. As soon as the AUT, dialog, or window is completely started, Silk4NET reduces the timeout again to the value you have specified for OPT_WAIT_RESOLVE_OBJDEF.
Object resolve retry interval (OPT_WAIT_RESOLVE_OBJDEF_RETRY)
If Silk4NET cannot immediately find an object, Silk4NET will retry to find the object until the object resolve timeout expires. The object resolve retry interval specifies the time in milliseconds that Silk4NET waits before retrying to find the object. The default value is 1000 milliseconds.
Object enabled timeout (OPT_OBJECT_ENABLED_TIMEOUT)
The maximum time in milliseconds that Silk4NET waits for an object to become enabled during playback. The default value is 1000 milliseconds.
Note: The timeouts do not overlap.

For detailed information about the automated synchronization that Silk4NET provides specifically for Web applications, see Page Synchronization for xBrowser. For detailed information about the synchronization that Silk4NET provides specifically for Ajax applications, see How to Synchronize Test Automation Scripts for Ajax Applications.

In addition to the automated synchronization, Silk4NET also enables you to manually add wait functions to your scripts. Silk4NET provides the following wait functions for manual synchronization:
WaitForObject
Waits for an object that matches the specified locator. Works with an xPath locator or an object map identifier.
WaitForProperty
Waits until the specified property gets the specified value or until the timeout is reached.
WaitForPropertyNotEquals
Waits until the value of the specified property no longer equals the specified value or until the timeout is reached.
WaitForDisappearance
Waits until the object does not exist or until the timeout is reached.
WaitForChildDisappearance
Waits until the child object specified by the locator parameter does not exist or until the timeout is reached.
WaitForScreenshotStable
Waits until the object is visually stable and does not change its position.

If a test randomly fails with an ObjectNotFoundException, increase the Object resolve timeout, for example to 30 seconds. For very specific long running operations, for example a click on an object that displays after a long calculation with a progress dialog, manually add the WaitForObject method to the test script, to wait until the object is found, or add the WaitForDisappearance method to the test script, to wait until the progress dialog is no longer displayed.

Automated synchronization example

Consider the following code sample, where Silk4NET tries to click on a button with the caption Ok:

'VB .NET code
Dim button = _desktop.PushButton("@caption='Ok'")
button.Click()
// C# code
var button = _desktop.PushButton("@caption='Ok'");
button.Click();
To replay the actions in this code sample, Silk4NET performs the following synchronization actions:
  1. Silk4NET tries to find the button. If the Object resolve timeout runs out, Silk4NET stops the replay and throws an exception.
  2. Silk4NET waits until the application under test (AUT) is ready. If the Synchronization timeout runs out before the AUT is ready, Silk4NET stops the replay and throws an exception.
  3. Silk4NET waits until the button is enabled. If the Object enabled timeout runs out before the button is enabled, Silk4NET stops the replay and throws an exception.
  4. Silk4NET clicks the button.
  5. Silk4NET waits until the application under test (AUT) is ready again.