When tracking single GUI elements with Ranorex Spy, Ranorex tries to specify the type or role of the element. What is it? Does the element represent a simple text box, button or a list item? What is the parent of the element? What is the type of the parent? Ranorex recognizes over 30 of the most commonly used types of GUI elements. In Ranorex vocabulary they are called 'adapters'. Every single element shown within the element tree of Ranorex Spy is represented by a Ranorex adapter. If Ranorex is not able to specify the type of adapter of a GUI 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' shows the general properties which are available for any type of GUI element. All the other information within the 'Overview' tab is related to the type of adapter provided.
// 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 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();
In addition to the Ranorex standard adapters which represent the logical view of a GUI element, Ranorex provides plug-in-dependent 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'.
// 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");
It is not required to work with Ranorex adapters. It's also possible to carry out test automation based on simple Ranorex elements - it's just more difficult.
Note: GUI objects managed within Ranorex repositories are always based on Ranorex adapters.