User-defined reporting | Ranorex
HomeUser GuideRanorex Studio FundamentalsUser-defined reporting

User-defined reporting

In addition to Ranorex standard reports and the options for customizing them, Ranorex provides a wide variety of additional user-defined reporting methods which are introduced and explained herein.

In this chapter

    Sample solution

    The herein introduced concepts of user-defined reporting methods are explained along with an example which can be downloaded here.

    Training! What do I do?

    Theme: User-defined reporting
    Time: Less than 30min

    Download sample file

    Installation:

    1. Unzip the project directory to any folder on your computer
    2. Start Ranorex Studio and open the solution file Introduction.rxsln

    Applying Ranorex standard report classes

    Applying one of the six different standard report classes based on user code is the easiest way of creating user-defined report messages.

    Further reading

    If you are not familiar with the concept of code modules and their application, we recommend reading > Ranorex Studio expert > Code modules > ⇢ Introduction.

    Ranorex standard report classes

    According to the introduced standard report levels, Ranorex provides six different report categories to be generated within user code reporting:

    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”);

    Applying Ranorex standard report classes

    Applying Ranorex standard report classes

    Create a code module SimpleReporting, or open it from the sample solution
    Add the class instantiations for the standard report classes in the Run() method
    Run the code module from the test suite and see the result
    Report messages of standard report classes

    Report messages of standard report classes

    tipp icon

    Hint

    Ensure to set the error level of the test suite to ‘Debug‘ level to display all standard report messages.

    Reporting with user code actions

    Beyond the option of applying user-defined reporting within code modules, it is, of course, possible to add them to recording modules by means of user-code actions.

    Further reading

    If you are not familiar with the concept of user-code actions and their application, we recommend reading > Ranorex Studio fundamentals > Actions > ⇢ User code actions.
    Switch to the recording module Recording1 (from the sample solution)
    Insertion of a user code action to a recording module

    Insertion of a user code action to a recording module

    Insert a new user code action ReportInformation() and double-click it to open it
    Test report message from user code action

    Test report message from user code action

    Add a new report information message to the constructor of the user code action

    Run the reporting module and see the report message in the test report

    Customizing report categories

    The default category of user-defined report messages is ‘User’. This default category can be changed at will.

    Temporary defined custom report category

    Create a new code module CustomReportCategory, or open it from the sample solution
    Open the code module and add the below introduced code
    Defining a temporary custom report category

    Defining a temporary custom report category

    Create a report message with a temporary defined custom report category
    Create a second report message with no definition of a custom report category
    Result(s): Run the corresponding code module and see the result.
    Temporarily set customized report category

    Temporarily set customized report category

    See the report messages with the temporarily set custom report category

    Permanently defined custom report category

    Create a new code module CustomReportCategory, or open it from the sample solution
    Open the code module and add the below-introduced code
    Defining a permanent custom report category

    Defining a permanent custom report category

    Define the permanent default custom report category
    Create report messages
    Result(s): Run the corresponding code module and see the result.
    Permanently set customized report category

    Permanently set customized report category

    See the report message with the permanently set custom report category

    User-defined report level

    With Ranorex, it is possible to create and apply user-defined report levels with name and value. Find the corresponding example in the code module CustomReportLevel of the sample solution.

    Definition of user-defined report levels

    Definition of user-defined report levels

    Define two user-defined report levels MID and LOW
    Apply the user-defined report levels with report messages
    Test report with user-defined report levels

    Test report with user-defined report levels

    See the corresponding report messages in the test report
    The user-defined report levels are applied accordingly

    Formatting a user-defined report level

    Formatting a user-defined report level

    Formatting a user-defined report level

    Define style format in CSS formatting syntax
    See the formatted result in the test report

    Setting current report level

    Report information will only appear in the report if its report level is higher than or equal to the report level of its test container. Find the corresponding example in the code module CustomReportLevel of the sample solution.

    Setting the current report level

    Setting the current report level

    Define two user-defined report levels
    Set the current report level to value MID, and higher
    Apply the setting by creating two report messages with different report levels

    Result(s):

    Run the code module and see the test report.

    Test report with level-filtered report messages

    Test report with level-filtered report messages

    Only report messages with report level MID and higher are included in the test report

    Overriding current report level

    The current report level can always be overridden by logging information with the report level ‘Always‘. Find the corresponding example in the code module CustomReportLevel of the sample solution.

    Overriding the current report level

    Overriding the current report level

    Define two user-defined report levels
    Set the current report level to value MID, and higher
    Apply the setting by creating two report messages, the second one overriding the current report level

    Result(s):

    Run the code module and see the test report.

    Overridden report level

    Overridden report level

    See the second report message overriding the current report level MID

    Reporting screenshots

    Screenshots of the current desktop can be easily sent to the report. Find the corresponding example in code module ReportingScreenshot of the sample solution.

    Reporting desktop screenshots

    Reporting desktop screenshots

    Add the code for sending a screenshot to the test report
    See the desktop screenshot in the test report
    Note icon

    Note

    It is possible to address certain UI-elements (i.e. repository items) for the screenshot. Refer to the corresponding section in an expert topic of this user guide to learn more.

    Further reading

    The addressing of repository items through code modules is introduced and explained in > Ranorex Studio expert > Code modules  > ⇢ Automating UI-elements out of repository.

    Reporting system summary

    The Ranorex reporting class provides a way to simply report a system summary. The corresponding example can be found in the code module ReportingSystemSummary in the sample solution.

    Reporting system summary

    Reporting system summary

    Add the code for sending the system summary to the test report
    See the system summary in the test report

    Adding customized data

    Within this section, we show you how to collect customized data during a test run and how to write these data into the XML test data file which is used to generate the final report.

    Adding custom data to test data file

    Triggering the customized data collection is done by means of a user code action with a method to be defined and which is responsible for tracking customized data. You find the corresponding example in the code module CustomData of the sample solution.

    Customized report data generation

    Customized report data generation

    Activity stack object definition

    • Define an object referencing the current activity stack of Ranorex
    • The activity stack is where all activities during a test run are collected by means of a stack data structure

    Add activity to the ‘activity stack’

    • The activity stack method CustomProperties puts a reported activity on to the activity stack
    • The method is defined by a custom field name (i.e. ‘myName’) and a custom field value (i.e. ‘myValue’), both of which are of type string

    Result(s):

    • The result is a custom data field pair in the corresponding data file
    Custom report data in test data file

    Custom report data in test data file

    Custom data in test data file

    • If you apply the test data outside of Ranorex report generation, feel free to parse the XML file the way you need to
    • If you need the customized test data to be included in Ranorex standard reporting, please refer to the next section

    Application of custom data

    If you want custom data within the XML test data file to be included into Ranorex reports, follow the instruction herein.

    Further reading

    If you are not familiar with XML and the corresponding concepts of CSS and XSL specifications, we recommend reading the corresponding topics at the website of the World Wide Web Consortium (W3C), at www.w3.org.

    Customization of XSL specification file

    To include custom data within Ranorex reporting it is necessary to customize the XSL specification of Ranorex reports. The customization of the XSL specification can be done with any XML editor, and of course, with Ranorex Studio. You find the corresponding XSL file in the project file folder /CustomDataTemplate/ of the sample solution.

    Customization of XSL specification

    Customization of XSL specification

     

     Identify field pair in test data file

      Option to print customized data introduction (header)
      Select the field value to the corresponding field name

    Result(s):

    Custom data in rest report

    Custom data in rest report

    Depending on the position within the XSL file specification, the Ranorex report contains the custom data