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.
Silk4J provides automated
test synchronization for all supported technologies, enabling you to build robust and manageable test sets. During the replay of a test,
Silk4J ensures that the test always waits until the AUT is ready to perform the next action. For a verification step in a test,
Silk4J 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
Silk4J 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,
Silk4J 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,
Silk4J 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
Silk4J cannot immediately find an object,
Silk4J will retry to find the object until the object resolve timeout expires. The object resolve retry interval specifies the time
in milliseconds that
Silk4J 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
Silk4J 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
Silk4J provides specifically for Web applications, see
Page Synchronization for xBrowser. For detailed information about the synchronization that
Silk4J provides specifically for Ajax applications, see
How to Synchronize Test Automation Scripts for Ajax Applications.
In addition to the automated synchronization,
Silk4J also enables you to manually add wait functions to your scripts.
Silk4J 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 property specified by the
propertyName parameter gets the value specified by the
expectedValue parameter 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.
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
waitForDissapearance method to the test script, to wait until the progress dialog is no longer displayed.
Automated synchronization example
Consider the following code sample, where
Silk4J tries to click on a button with the caption
Ok:
PushButton button = _desktop.find("//PushButton[@caption='ok'");
button.Click();
To replay the actions in this code sample,
Silk4J performs the following synchronization actions:
- Silk4J tries to find the button. If the
Object resolve timeout runs out,
Silk4J stops the replay and throws an exception.
-
Silk4J waits until the application under test (AUT) is ready. If the
Synchronization timeout runs out before the AUT is ready,
Silk4J stops the replay and throws an exception.
- Silk4J waits until the button is enabled. If the
Object enabled timeout runs out before the button is enabled,
Silk4J stops the replay and throws an exception.
- Silk4J clicks the button.
-
Silk4J waits until the application under test (AUT) is ready again.