Complex report customization

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.

Further reading

If you are not familiar with the concept of code modules and their application, refer to Ranorex Studio expert > ⇢ Code modules.
In this chapter

    Download the sample solution

    The examples in this chapter are based on a sample solution that you can download from the link below.

    Sample solution

    Theme: Complex report customizations
    Time: 30 minutes

    Download sample file

    Install the sample solution:

    Unzip to any folder on your computer.
    Start Ranorex Studio and open the solution file RxDatabase.rxsln

    tipp icon


    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 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.
    Applying Ranorex standard report classes
    Run the code module from the test suite to see the results in the report.
    Report messages of standard report classes

    Report messages from standard report classes

    tipp icon


    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.

    Further reading

    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.
    Insertion of a user code action to a recording module
    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.
    Test report message from user code action

    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.
    Defining a temporary custom report category

    Defining a temporary custom report category

    This report message appears under the category Cat.A.
    This report message appears under the default category User.


    Temporarily set customized report category
    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.
    Defining a permanent custom report category

    Defining a permanent custom report category

    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.


    Permanently set customized report category
    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.
    Definition of user-defined report levels


    Test report with user-defined report levels
    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.
    Formatting a user-defined 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.
    Setting the current report level


    Test report with level-filtered report messages
    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.

    Overriding the current report level

    Overriding the current report level

    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.


    Overridden report level
    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.
    Reporting desktop screenshots
    The desktop screenshot in the test report.

    Further reading

    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.
    Reporting system summary
    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 ( that’s 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).
    Customized report data generation


    • The result is a custom data field pair in the corresponding data file
    Custom report data in test 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

    Further reading

    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 in Ranorex Studio.

    Add the code in the picture below to the file.

    Customization of XSL specification
    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.


    Custom data in rest report
    The report contains the custom data.