Ranorex Test Suite, Test Module Creation, UserCode File, Xpath, and Data Binding

In the previous Ranorex part 1 tutorial, we discussed the basic components of Ranorex Studio. Ranorex Studio offers a wide range of tools to make automation testing an easier one.

However, Ranorex is considered to be an important automation testing tool with excellent features in it. It is very simple and easy to use Ranorex. Let’s dive deep into other factors involved in Ranorex.

In this tutorial, we will get to know about a test suite & test module creation, the UserCode file, Editing the Xpath, Data Binding and Ranorex Report in detail.

What You Will Learn:

Modifying UserCode file

As discussed earlier, a recording file is made up of two files, .cs and .UserCode.cs file. .cs file cannot be modified. Any changes to the steps or further validations can be added only in the .UserCode file. .cs file is system generated and is used during compilation. User code is used for custom code entry.

Let us create a test and modify the actions using .UserCode file. Follow the general steps to create a Ranorex project and record a test by using the recording module.

Refer to the image below:

A Project by name UserCodeProject.rxtst is created. It has a recording module renamed as UserRecord..rxrec. I have recorded a simple test of opening MyComputer window from Start and closing the window.

Open the .cs file of the recording module.

It will look like something as shown below:

The ITestModule is the base interface that is implemented by a Run method.  The Run method calls will contain all the recorded steps.

Let’s consider the above E.g, it has Clicking on Start Button, Clicking on Computer followed by Closing. This file gets compiled and executed during each Run, and it is generated automatically based on the recorded steps and modified userCode. Hence no changes can be made to this.

Now let’s see how we can add or edit the UserCode file. The UserCode file without any entry will have only Init method.

Now, I am going to add a new method to UserCode file, OpenControlPanel()

Go back to Recording file (.rxrec) where all the steps will be in tabular form. Now try to add this newly created method.

Click on Confirm Selection. And the method gets saved as a step in the recording file.

Now let us check what has happened to .cs file.

As and when the application becomes complex, the conditions to be tested also grows. And so, grows

the test scripts. Hence, it is very much necessary to have them divided into smaller identifiable modules. The OpenControlPanel() has been automatically added to the.cs file after saving the recorder file. Hence we can directly jump to the generated code of any recorded steps by simply clicking on the step and clicking the View Code option.

Test Cases and Test modules

We came to know how to create and modify test steps from the above example. Now we will look at the ease of dividing these test steps into modules for better maintenance. As and when the test size increases, the number of steps also increases. Further, it will become too difficult to maintain.

Let us create a test suite and a recording module in it.

Here, Recording1 is the first recording module for TestCase1. Now let’s see how to create multiple recording modules for TestCase1.

Click on the TestCase1 and select the Add option. Under Add, you have a drop-down as New recording Module. Click on that and give a name to the recording module.

I have created three recording modules for TestCase1 as shown below.

Each recording module can have their own test steps inside them. It is also possible to Move, Cut, Copy and Paste the test steps from one recording module to another.

Data Binding

This is one of my favorite topics in Ranorex. Often our tests will be based on different set of Inputs. We test our application for a state with different input conditions and then verify the output. This is called Data Driven Testing and Ranorex offers a feature called Data Binding to bind the different Input conditions to the test case.

To bind the data, click on the Test case => Select Data Binding

Ranorex offers data binding in 4 ways, as shown in the below image:

I am creating a simple data table. We can give any name to our data table. Here I’m going to keep the default name NewConnector1.

Now let us create two Input parameters as Input Number1 and InputNumber2. This can be done by clicking on Add column.

So, I have two sets of Input. Enter the input values. Click on Apply and Click ok to close the Data binding window. Now let us create an Add method in the recording1 module.

Open the UserCode of Recording1 and write an Add method which will take two parameters as Input.

Include this method in the recording module.

Now Data bind the Input values. Give a Name to the new variables and you can keep the default value.

Go back to the test case, Open Data Binding, Click on Data Binding tab and map the Module variable to Data Column. Click on Apply and Close the window.

So, when every time, ADDNumbers method is called, the input values are taken from the data binding table. This makes Data Driven testing easier and maintainable. Such data can also be created for a test suite, by selecting Global Parameter option from the drop-down.

Editing Xpath

Ranorex Xpath is a powerful identifier of UI elements. Each repository item refers to a Ranorex Xpath. As we have seen in our previous tutorial, Ranorex Spy is used to create the mapping of UI item and add it to the repository file of the test case.

We often come across code logic, where we will need to edit the Xpath for identifying the type of elements required for our test. There are two ways of editing the Xpath: Using Path editor and Editing the path directly in the textbox of Spy itself.

For Example, I ran Spy on a Calculator app and it listed the repository items.

As shown in the below image:

Let’s say that we want a list of all the buttons in a calculator. This can be achieved by editing the path of any button under WinApp ‘Calculator’. Click on the text box path in the top of element browser, press <Ctrl><Space> together to enable the editing.

After editing the path as shown below, we get a list of the buttons under a Calculator. Observe the change in the hierarchy of elements in the Browser Results also.

Right-click on any element and select Add to a repository, to add it to the current test case repository and refer that in test case file for implementing the code logic.

Another way of editing a UI Xpath is through Path editor. Go to repository file. Choose the element that you want to edit, and click on the Edit button beside it. This will open the spy in the Path Editor mode where similar changes can be made.

Ranorex Reporting

After execution of a test suite, Ranorex report typically looks as shown below:

It gives an Overview of:

Screenshots can be included in the report by using the Report.Screenshot() method. Screenshots help in fast identification of issues. By clicking on the Screenshot in a report, it can be maximized for better clarity.

There are different types of Report levels. Report levels define the kind of output shown in the report.

Few of the pre-defined report levels include:

The above can be used in the code as follows:

Reports can also be customized by changing the reporting parameters in test suite properties.

Integrating Ranorex with Visual Studio

It is possible to use Ranorex with Visual Studio instead of directly creating projects in the Ranorex. All we need to do is add Ranorex assemblies in VS.

Given below are the main assemblies of Ranorex that should be added:

  1. Ranorex.Core
  2. Ranorex.Common
  3. Ranorex.Bootstrapper
  4. All Ranorex.Plugin assemblies

Steps to be followed:

Ranorex.Core.Resolver is the assembly which fetches all other assemblies of Ranorex. So it is essential to initialize this by setting it to True, before we start writing the code.


In this tutorial, we understood all the deeper layers of Ranorex, especially the usage of UserCode file and Xpath. Also, about Data binding which is a very important feature of Ranorex.

The crux is as below:

Ranorex as a tool, covers all the requirements of an automation testing tool, with GUI object recognition, Data Driven Testing, Reusable code Modules, Record and Playback, Keyword driven testing and so on. It is suitable for all applications, Web, Desktop, and mobile. Recently Ranorex has announced its integration with Selenium also.

=> Click here if you want to go back and read tutorial #1.

Share your experience on working with Ranorex and let us know if you have any queries.