In this tutorial, we will get to know about Ranorex test suite & test module creation, the UserCode file, Editing the Xpath, Data Binding, and Ranorex Report in detail.
In the previous Ranorex part 1 tutorial, we discussed the basic components of Ranorex Studio. Ranorex Studios offers a wide range of tools to make automation testing easier.
However, Ranorex is considered to be an important automation testing tool having some excellent features in it. Ranorex is very simple and easy to use. Let’s dive deep into other factors involved in Ranorex through this article.
Table of Contents:
Ranorex
Modify the UserCode file
As discussed earlier, the 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 validation can only be added to 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 using the recording module.
Refer to the image below:
A Project by the name UserCodeProject.rxtst has been created. There is a recording module renamed UserRecord…rxrec. I have recorded a simple test of opening the MyComputer window from Start and closing the window.
Open the .cs file for the recording module.
It will look like something as shown below:
ITestModule is a base interface that is implemented using a Run method. The Run method calls will contain all the recorded steps.
Please consider the above E.g., it has Clicked on Start Button, Click 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 user code. 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 only have the Init method.
I am going to add a new method to the UserCode file, OpenControlPanel()
Go back to the Recording file (.rxrec) where all the steps will be in tabular form. Now try to add this newly created method.
Click on Confirm Selection. 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 grow. And so, grows
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, you can jump directly to the generated code for any recorded steps by simply clicking on the step and clicking on the View Code option.
Test Cases and Test Modules
We came to know how to create and modify test steps from the above example. We will now 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. Furthermore, 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 TestCase1 and select the Add option. Under Add, you have a drop-down as a 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 its 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 sets 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 image below:
- Simple Data table
- CSV Connector
- Excel Connector and
- SQL Connector
I am creating a simple data table. You can give any name to our data table. 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 the Add column.
So, I have two sets of Inputs. 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.
Data is now bound to 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 the Data Binding tab and map the Module variable to the Data Column. Click on Apply and Close the window.
So, every time the 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 the Global Parameter option from the drop-down.
Editing XPath
The 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 items and add them to the repository file of the test case.
We often come across code logic, where we will need to edit the Xpath to identify the type of elements required for our test. There are two ways of editing the Xpath: Using the 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 image below:
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 at the top of the element browser, and 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, add it to the current test case repository and refer to that in the test case file to implement the code logic.
Another way of editing a UI Xpath is through the Path editor. Go to the repository file. Choose the element that you want to edit, and click on the Edit button beside it. This will open up a spy in Path Editor mode where similar changes can be made.
Ranorex Reporting
After execution of the test suite, Ranorex’s report typically looks as shown below:
It gives an Overview of:
- How many tests were executed?
- Name of the test suite, recording module, and steps.
- System and operating system details.
- Duration of execution.
- Pass/Fail details.
- Pie chart which color codes the result of execution i.e., green when successful and red when failing.
- In the case of iterations, where the same steps are performed for a different set of Input values, the iteration details will also be shown in the report such as Iteration 1, Iteration 2, and so on.
- One can filter the log messages by checking and unchecking checkboxes in the Test Container Filter.
Screenshots can be included in the report by using the Report.Screenshot() method. Screenshots help in the faster identification of issues. By clicking on the Screenshot in the report for better clarity.
There are different types of Report levels. Report levels define the kind of output shown in the report.
A few of the pre-defined report levels include:
- Debug
- Infor
- Success
- Failure
- Warning
The above can be used in the code as follows:
Reports can also be customized by changing the reporting parameters in the test suite properties.
Integrating Ranorex with Visual Studio
You can use Ranorex with Visual Studio instead of directly creating projects in Ranorex. All we need to do is add Ranorex assemblies in VS.
Given below are the main assemblies of Ranorex that should be added:
- Ranorex.Core
- Ranorex.Common
- Ranorex.Bootstrapper
- All Ranorex.Plugin assemblies
Steps to be followed:
- Open Visual Studio.
- Create a New Project.
- Select .Net version (4.5.2 and higher).
- Create a Console Application.
- Once the project is created, right click on References to add Ranorex assemblies.
- Ranorex assemblies will be present in the bin folder, usually C:\Program Files (x86)\Ranorex <version>\bin.
Ranorex.Core.Resolver is an assembly that fetches all other assemblies of Ranorex. So it is essential to initialize this by setting it to True before we start writing the code.
Conclusion
In this tutorial, we understood all the deeper layers of Ranorex, especially the usage of the UserCode file and Xpath. Data binding is also a very important feature of Ranorex.
The crux is as below:
- Ranorex recording module has two files: .cs and.UserCode file.
- UserCode file is for modification and further addition of code logic and the .cs file cannot be manipulated.
- A test suite can have multiple test cases and each test case can have multiple test modules. Test modules help in the maintenance of code logic in the case of numerous test steps.
- Data Binding offers ease of testing with multiple inputs and different iterations.
- Xpath can be edited by the Path editor or just by clicking directly on the text box.
- Ranorex is a comprehensive display of the test results. It can also be customized according to our needs.
- Integrating Ranorex with VS IDE is easy, it is done just by adding the references in the solution.
Ranorex is a tool that covers all the requirements of an automation testing tool with GUI object recognition, Data-Driven Testing, Reusable code Modules, Record and Playback, and Keyword-driven testing. It is suitable for all applications, Web, Desktop, and mobile. Ranorex has recently announced its integration with Selenium as well.
=> Click here if you want to go back and read tutorial #1.
Share your experience working with Ranorex and let us know if you have any queries in the comments section below. We would love to hear from you.
very useful tutorial.
clean and neat explanation which helps in understanding the tool lot better.