Ranorex Help Center How can we help you?

Ranorex UI Adapter

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.

Properties of a Ranorex 'Text' Adapter

Properties of a Ranorex 'Text' Adapter

Properties of a Ranorex 'TreeItem' Adapter

Properties of a Ranorex 'TreeItem' Adapter

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.


The following example accesses properties of a Ranorex Text adapter:

// Create Text adapter from RanoreXPath  
Text textBox = "/form[@controlname='TestedApp']/text[@controlname='label3']";  
// 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[@controlname='TestedApp']/text[@controlname='label3']"  
' 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  




The following example accesses properties of a Ranorex TreeItem adapter:
// Create TreeItem adapter from RanoreXPath  
TreeItem treeItem= "/form[@title='TreeView Test']/?/?/?/treeitem[@text='TreeItem']";  
// Collapse and expand tree item  
if (treeItem.Expanded)  
  treeItem.Collapse();  
else  
  treeItem.Expand();  



' Create TreeItem adapter from RanoreXPath  
Dim treeItem As TreeItem = "/form[@title='TreeView Test']/?/?/?/treeitem[@text='TreeItem']"  
' Collapse and expand tree item  
If treeItem.Expanded Then  
    treeItem.Collapse()  
Else  
    treeItem.Expand()  
End If  



Multiple Adapters for one GUI element

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:

Button of calculator application which provides a Ranorex Button and a Ranorex NativeWindow Adapter

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

Button of a .NET WinForms application which provides an additional Ranorex Control adapter

The Control adapter, which is available for .NET WinForms applications, allows Ranorex to access more properties in the application under test, like the background color or font size of the displayed text. Simply convert a standard Button adapter to a WinForms Control adapter as follows:

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