Synchronization
In the world of testing mostly static HTML pages synchronization was easy. Telerik Testing Framework was even able to automatically take care of synchronization for you (most of the time). All you had to do was click on a button and wait for the browser to be ready, which the framework does behind the scenes for most HTML UI actions.
In the world of Silverlight application testing, unlike testing static HTML web pages, you have to intelligently implement synchronization with the Silverlight application under test. This is because in the Silverlight world you're dealing with a real application that is running locally in the browser. The "browser is ready" indicator no longer applies since it only told you when the browser was finished loading the web page from the server.
The framework has many features implemented to aid you in synchronizing with your Silverlight application as it's being tested. There are six basic types of waits implemented in the framework that you can use for synchronization:
Wait Type | Description |
---|---|
ForExists | This method waits for the element to exist in the Visual Tree. It accepts an optional timeout parameter. |
ForExistsNot | This method waits for the element to no longer exist in the Visual Tree. It accepts an optional timeout parameter |
ForVisible | This method waits for the element to both exist in the Visual Tree and its Visibility attribute to equal "Visible". It accepts an optional timeout parameter. |
ForVisibleNot | This method waits for the Visibility property of the element to not equal 'Visible' or for the element to no longer exist in the Visual Tree. It accepts an optional timeout parameter. |
ForNoMotion | This method waits for the element to stop moving on the drawing surface. It takes a check interval and an optional timeout parameter. |
For(Predicate) | This method takes a custom predicate and waits for that predicate to return true. It accepts an optional error message and an optional timeout parameter. |
Waiting for an Element to Exist
Before you can use the VisualWait.ForExists method to wait for an element to exist you need to create what is called an "Element Proxy". An element proxy is a lightweight FrameworkElement that doesn't actually represent a real element but contains information on how to find the desired element in the Visual Tree. To create an element proxy implement code like this:
Now that you have an element proxy you use it to wait for the element to exist using this line of code:
Using ForExistsNot, ForVisible, ForVisibleNot, ForNoMotion
Using any of these functions is pretty straightforward. Just call the method with appropriate parameters, for example:
Creating Your Own Wait Condition
If none of the built-in framework wait for methods meet your needs, the framework has the ability to use your own coded conditional predicate instead. This feature relieves you of the burden of having to fully implement your own custom wait loop.
You can implement your conditional predicate in a function or a lambda expression. Here is a sample of how to implement and use your own conditional predicate in a function:
To do the same thing in a lambda expression would look like this: