When tracking single UI elements with Ranorex Spy, Ranorex tries to specify the role and technology of the element. Ranorex recognizes over 30 of the most commonly used types of UI elements. In Ranorex vocabulary these types are called 'adapters'. Every single element shown within the element tree of Ranorex Spy can be accessed using the Ranorex UI adapters that the element supports. If Ranorex is not able to assign a more specific type of adapter to a UI element, it will be displayed as 'Unknown'.
Ranorex adapters provide more convenience when creating automated tests. Here is an example: A Ranorex Text adapter provides text box related properties like 'Text' or 'SelectionText'. In comparison to a simple Text adapter, a Ranorex TreeItem adapter provides tree item specific properties and methods like expand or collapse. Ranorex Spy shows all adapter related properties in the 'Overview' tab.
The section 'General' in Ranorex Spy shows the general properties which are available for any type of UI element. All the other information within the 'Overview' tab is related to the type of adapter supported by the element.
// Create Text adapter from RanoreXPath
Text textBox = "/form[@title='Calculator']/text[@controlid='403']";
// Set text value of text box
textBox.TextValue = "12";
// Check on of the 'General' properties
if (textBox.Enabled)
Report.Info("Text is enabled");
' Create Text adapter from RanoreXPath
Dim textBox As Text = "/form[@title='Calculator']/text[@controlid='403']"
' Set text value of text box
textBox.TextValue = "12"
' Check on of the 'General' properties
If textBox.Enabled Then
Report.Info("Text is enabled")
End If
// Create TreeItem adapter from RanoreXPath
TreeItem treeItem= "/form[@title='Documents and Settings']/*/*/*/*
/*/*/treeitem[@text='Documents and Settings']";
// Collapse and expand tree item
if (treeItem.Expanded)
treeItem.Collapse();
else
treeItem.Expand();
' Create TreeItem adapter from RanoreXPath
Dim treeItem As TreeItem = "/form[@title='Documents and
Settings']//treeitem[@text='Documents and Settings']"
' Collapse and expand tree item
If treeItem.Expanded Then
treeItem.Collapse()
Else
treeItem.Expand()
End If
In addition to the Ranorex standard adapters which represent the logical view of a UI element, Ranorex provides technology-specific adapters with more information.
As an example the Ranorex WinForms Plug-In is able to provide more information about a simple button in a .NET application. This additional information is provided via an additional adapter called 'Control'. The following screenshots compare the information shown by Ranorex Spy for a Win32 and a WinForms button:
// Create Button adapter with RanoreXPath
Ranorex.Button button= "/form[@controlname='TestedApp']
/button[@controlname='button1']";
// Convert Button adapter to Control adapter
Ranorex.Control winFormsButton = new Ranorex.Control(button);
// Call 'GetPropertyValue' method provided by the Control adapter
Color color = winFormsButton.GetPropertyValue<Color>("BackColor");
' Create Button adapter with RanoreXPath
Dim button As Ranorex.Button = "/form[@controlname='TestedApp']
/button[@controlname='button1']"
' Convert Button adapter to Control adapter
Dim winFormsButton As New Ranorex.Control(button)
' Call 'GetPropertyValue' method provided by the Control adapter
Dim color As Color = winFormsButton.GetPropertyValue(Of Color)("BackColor")
It is not required to work with Ranorex adapters. It's also possible to write automation code using Ranorex Element instances (which are used internally by Ranorex adapters) - it's just more difficult.
Note: UI objects managed within Ranorex repositories always use Ranorex adapters.
Download Test Automation Guide
(PDF file, 20MB)