Invoking Actions on Elements
Once you have found an element you can then interact with it. Many different types of interactions are supported like clicking, mouse hover over, mouse wheel-related actions, keyboard clicks etc.
1. Clicking On an Element - invoke a click on a FrameworkElement.
2. Sending Text to a Control - type text content into a FrameworkElement.
3. Mouse Actions - invoking different mouse actions on FrameworkElement.
4. Framework Element Properties and Actions. * UI Element Actions - understanding wrappers. * Telerik Testing Framework Specific Properties - commonly used Properties of Telerik's FrameworkElement. * Telerik Testing Framework Specific Methods - commonly used Methods of Telerik's FrameworkElement. * Getting and Setting Properties on Elements - working with non-built in Properties. 5. Invoking Element Methods - invoke any method attached to an element.
Clicking On an Element
To invoke a UI action, use the User object that is attached to every UI element. For example, to click on an element such as a button, enter code like this:
Sending Text to a Control
To send text to the control use one of the following lines of code:
Mouse Actions
To perform one of the various possible mouse actions use one of the following lines of code:
Framework Element Properties and Actions
All of the Telerik Testing Framework UI controls derive from the FrameworkElement object. Our FrameworkElement object mirrors as closely as possible XAML's FrameworkElement as defined in MSDN here. For customers interested in our extensibility model, the Silverlight Extension does not expose a UIElement and therefore, our FrameworkElement can be viewed as the combination of Silverlight/WPF's UIElement + FrameworkElement. These are just few examples of the many available properties of our FrameworkElement object:
Retrieves a list of elements that are children of this element in the visual tree.Property | Description |
---|---|
AutomationId | Retrieves the Automation ID assigned to this element. |
Children | |
Clip | Gets or sets the Geometry used to define the outline of the contents of a UI Element. |
Height | Gets or sets the suggested height of a FrameworkElement. |
Opacity | Gets or sets the degree of the object's opacity. |
OpacityMask | Gets or sets the brush used to alter the opacity of regions of this object. |
Width | Gets or sets the suggested width of a FrameworkElement. |
UI Element Actions
Each UI element wrapper class contained in Telerik Testing Framework has a set of properties used to access the properties appropriate for that UI element. For example: The Calendar control has a SelectedDate property that you can use to read and/or set the currently selected date of the control. It also has a SelectionMode property you can use to read and/or change the selection mode from a single date to a multi-range date selection. The CheckBox control has an IsChecked property you can use to read/set the checked state of the control and so on.
Telerik Testing Framework Specific Properties
We have implemented a few special properties in our FrameworkElement object to aid in automation. These include:
Property | Description |
---|---|
AbsoluteSiblingTagIndex | Returns the sibling tag index of this FrameworkElement relative to its other siblings within the Visual Tree. |
AbsoluteTagIndex | Returns the absolute index of this XAML tag within the entire Visual Tree. |
Application | Gets the Application object that owns this element. |
EnableValidateMouseLocation | Enables or disables the validation of mouse click locations before performing mouse actions. |
Find | Gets the Find object that can be used to search the visual children of this element. |
TagNameIndex | Gets the tag name index of the XAML tag name in the visual tree. |
User | Gets the UI interaction object which allows you to interact with this framework element directly using real mouse and keyboard interactions. |
Wait | Gets a VisualWait object you can use to wait for Visual elements in the Visual Tree. |
XamlTag | Gets the XAML tag name of this FrameworkElement. This is used for hierarchy matching and traversal. |
Telerik Testing Framework Specific Methods
The FrameworkElement class implements a number of methods just for purpose of test automation. Some of the most commonly used include:
Property | Description |
---|---|
CastAs<T>() | Returns a FrameworkElement as a strongly-typed control. Does not enforce a tagname to match the type. |
GetChildren() | |
GetNextSibling() | Returns the next sibling of the FrameworkElement. |
Parent() | Returns the parent element of the current Framework Element |
ScrollToVisible() | Scrolls the browser so that the Framework Element is visible. |
Getting and Setting Properties on Elements
If the property of an element you want to get or set isn't available as a property in the UI element wrapper object, you can use the GetProperty and SetProperty from the FrameworkElement object to get/set it. This is especially useful if you start designing your own custom Silverlight UI controls or use a third party custom control. Let's suppose I have a UI element that represents an airline ticket. One of the many obvious properties such a control would need to have is flight number. To fetch this property from the control I can use code like this:
Invoking Element Methods
Another advanced feature of the framework is the ability to invoke any method attached to an element. Here's how to invoke the ScrollToVerticalOffset method of a ScrollViewer element.