In this chapter, you’ll find instructions on how to perform a range of more complex report customizations. Since they require coding skills, you should be familiar with code modules in Ranorex Studio.
If you are not familiar with the concept of code modules and their application, refer to Ranorex Studio expert >Code modules.
Download the sample solution
The examples in this chapter are based on a sample solution that you can download from the link below.
Theme: Complex report customizations
Time: 30 minutes
Install the sample solution:
-
Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
RxDatabase.rxsln
The sample solution is available for Ranorex Studio versions 8.0 or higher. You must agree to the automatic solution upgrade for versions 8.2 and higher.
The standard report classes
The easiest way to create a report message in code is by using one of the six different standard report classes.
Standard report classes
Ranorex Studio has six standard report classes, as shown below. These classes correspond to the standard report levels.
Ranorex.Report.Debug(“Debug message”);
Ranorex.Report.Info(“Information message”);
Ranorex.Report.Warn(“Warning message”);
Ranorex.Report.Error(“Error message”);
Ranorex.Report.Success(“Success message”);
Ranorex.Report.Failure(“Failure message”);
-
Create a code module and open it.
-
Add the class instantiations for the standard report classes in the Run() method.
-
Run the code module from the test suite to see the results in the report.
Make sure the report level of the test suite is set to Debug to display all report messages.
Report with user code actions
In addition to using code modules, you can also create report messages in recording modules with user code actions.
To learn more about user code actions, refer to: Ranorex Studio fundamentals > Actions > User code actions.
-
Open a recording module.
-
Insert a new user code action called
ReportInformation()
and open it.
-
Add a new report information message to the constructor of the user code action.
-
Run the recording module to see the report message in the test report.
Customize the default report category
By default, the category of custom report messages is User. You can change this to a different value, either on a per-message basis or for all messages until you change it back.
Per message
-
Create a new code module and open it.
-
Add the code shown below.
-
This report message appears under the category Cat.A.
-
This report message appears under the default category User.
Result:
-
The report messages with their categories as defined above.
Change default category
-
Create a new code module and open it.
-
Add the code shown below.
-
This line defines Cat.A as the new value for the default category for user-defined report messages.
-
These report messages appear under the new default category.
Result:
-
User-defined messages appear under the category Cat.A until you change it.
Define custom report levels
You can define report levels with a custom name and value.
-
Define the custom report levels MID and LOW using the code below.
-
Create two user-defined report messages with the new report levels.
Result:
-
The report messages appear with the new report levels.
Format custom report levels
-
Add the code below to apply custom CSS formatting to a report level.
-
See the formatted result in the test report
Set threshold report level with custom report levels
In this example, you’ll set the threshold report level for messages using a custom report level.
-
Define two custom report levels.
-
Set the current threshold report level to MID and higher.
-
Create two report messages, one with LOW and one with MID as report levels.
Result:
-
Only report messages with the report level MID and higher appear in the report.
Override current report level
You can override the current report level with the special report level Always.
-
Define two custom report levels.
-
Set the current threshold report level to MID and higher.
-
Create two report messages, one overriding the current report level.
Result:
-
The second message appears regardless of the current report level.
Report screenshots
-
Add the code below to send a screenshot to the report. If you don’t specify a repository item, Ranorex Studio takes a screenshot of what’s visible at the time of code execution.
-
The desktop screenshot is in the test report.
To learn how to take screenshots of specific repository items, refer to Ranorex Studio expert > Code modules.
Report a system summary
-
Add the code below to display a system summary in the report.
-
The system summary appears as an Info message in the report.
Add customized data
You can collect customized data during a test run and write it to the raw data file (.rxlog.data) that are used to generate the final report.
Add custom data to raw data file
Customized data collection is triggered by a user code action with a method that tracks customized data.
-
Define an object that references the current activity stack of Ranorex Studio.
The activity stack is where all activities during a test run are collected by means of a stack data structure. -
Add an activity to the activity stack.
The activity stack method CustomProperties adds a reported activity to the activity stack. It is defined by two strings, name (e.g. myName) and value (e.g. myValue).
Result:
- The result is a custom data field pair in the corresponding data file
-
The raw data file contains the custom data.
- If you want to apply the test data outside of Ranorex Studio report generation, you can parse the XML file as needed.
- To include the custom data in a Ranorex Studio report, please refer to the next section.
Include custom data in report
If you are not familiar with XML and the corresponding concepts of CSS and XSL specifications, we recommend the website of the World Wide Web Consortium (W3C) for more information.
To include custom data in Ranorex Studio reports, you must modify the corresponding XSL specification file of the report. You can do this in any XML editor or Ranorex Studio.
-
Add the code in the picture below to the file.
-
This line identifies the field pair where the custom data is located in the raw data file.
-
This optional line adds a header that will be displayed before the custom data.
-
This line gets the field value of the corresponding field name.
Result:
-
The report contains the custom data.