Ranorex GUI Adapter

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.

Properties of a Ranorex 'Text' Adapter
Properties of a Ranorex 'TreeItem' Adapter

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.

Access properties of Ranorex Text adapter.

C#

// 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");

VB.NET

' 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

Python

# Create Text adapter from RanoreXPath
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")
Access properties of Ranorex TreeItem adapter.

C#

// 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();

VB.NET

' 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

Python

# Create TreeItem adapter from RanoreXPath
treeItem = "/form[@title='Documents and Settings']//treeitem[@text='Documents and Settings']"
# Collapse and expand tree item
if treeItem.Expanded:
	treeItem.Collapse()
else:
	treeItem.Expand()

Multiple Adapters for one GUI element

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'.

Button of calculator application which provides a Ranorex Button and a Ranorex NativeWindow Adapter
Button of a .NET WinForms application which provides an additional Ranorex Control adapter
The Control adapter, which is available for .NET WinForms application, allows Ranorex to invoke the application under test to access more properties like the background color or font size of the displayed text. Simply convert a standard Button adapter to a WinForms Control adapter as follows:

C#

// 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");

VB.NET

' 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")

Python

# Create Button adapter with RanoreXPath
button = "/form[@controlname='TestedApp']/button[@controlname='button1']"
# Convert Button adapter to Control adapter
winFormsButton = Ranorex.Control(button)
# Call 'GetPropertyValue' method provided by the Control adapter
color = winFormsButton.GetPropertyValue("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.