English|Deutsch
Subscribe Ranorex Announcements Feed Ranorex LinkedIn Ranorex twitter Ranorex Facebook Ranorex Google+

Reporting & Logging

This Documentation is only for Ranorex 2.x versions.

Click here for the Ranorex 3.x test automation documentation

The Ranorex Report class is used to generate test execution reports during test automation. Each Ranorex based test should log at least two messages showing the start and end time of the test. The more information is logged during automation, the easier it is to find out what went wrong - as long as the generated report can be filtered too.

The Ranorex Report class provides several methods to distinguish between important test or validation logs and simple test development debug information.

All reported information is stored as a XML file.

Test execution succeeded
Test execution failed

How to handle log levels and test results

During test development it is often necessary to log messages showing more developer specific information, therefore the Report class provides four different methods and log levels for test developers.

C#

// Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true);
// Alternatively append the reports to an existing file as follows
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true, true);

// Log four different levels
Report.Debug("Debug message");
Report.Info("Info message");
Report.Warn("Warning message");
Report.Error("Error message");

// Log HTML content
string htmlString = "<b style=\"color: #ee0000; border: 1px solid #ee0000; padding: 2px;\">Your HTML content</b>";
Report.LogHtml(ReportLevel.Info,htmlString);

// Stop Report - log file will be finished
Report.End();

VB.NET

' Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", True)

' Log four different levels
Report.Debug("Debug message")
Report.Info("Info message")
Report.Warn("Warning message")
Report.Error("Error message")

' Log HTML content
string htmlString = "<b style=\"color: #ee0000; border: 1px solid #ee0000; padding: 2px;\">Your HTML content</b>"
Report.LogHtml(ReportLevel.Info,htmlString)

' Stop Report - log file will be finished
Report.End()

Python

# Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", True)

# Log four different levels
Report.Debug("Debug message")
Report.Info("Info message")
Report.Warn("Warning message")
Report.Error("Error message")

# Log HTML content
string htmlString = "<b style=\"color: #ee0000; border: 1px solid #ee0000; padding: 2px;\">Your HTML content</b>"
Report.LogHtml(ReportLevel.Info,htmlString)

# Stop Report - log file will be finished
Report.End()
Test developer related log levels

From the perspective of a test manager, it's more important to know whether the test failed or not. Use the following methods to log more test specific information. Additionally the Validate class automatically reports successful or unsuccessful validations.

C#

// Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true);

// Log test specific information
Report.Failure("Test case failed");
Report.Success("Test case successfully finished");
Ranorex.Validate.AreEqual("compareText", "compareText","String comparison", true);

// Log current system environment
Report.SystemSummary();
Report.End();

VB.NET

' Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", True)

' Log test specific information
Report.Failure("Test case failed")
Report.Success("Test case successfully finished")
Ranorex.Validate.AreEqual("compareText", "compareText", "String comparison", True)

' Log current system environment
Report.SystemSummary()
Report.End()

Python

# Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", True)

# Log test specific information
Report.Failure("Test case failed")
Report.Success("Test case successfully finished")
Ranorex.Validate.AreEqual("compareText", "compareText", "String comparison", True)

# Log current system environment
Report.SystemSummary()
Report.End()
Test Report messages

Appending to an Existing Log File

If it is required to have only one log file, which contains all the information reported during older test runs, simply set the property 'AppendExisting' to true, or use the 4th parameter of the 'Report.Setup' method.

C#

// Setup XMLLogger to append to an existing file ...
XmlLogger.AppendExisting = true;

// ... or use the 4th optional parameter value to true
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true, true);

VB.NET

' Setup XMLLogger to append to an existing file ...
XmlLogger.AppendExisting = true

' ... or use the 4th optional parameter value to true
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true, true)

Python

# Setup XMLLogger to append to an existing file ...
XmlLogger.AppendExisting = true

# ... or use the 4th optional parameter value to true
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true, true)

Screenshot reports offer more information

The Report class also supports a method to create screenshots to log images from applications or unexpected dialogs. Every Ranorex test should handle exceptions and generate at least one screenshot from the system's desktop, providing more information about the status at the time of termination.

C#

// Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true);

// Get calculator application and one element
// just for screen shot report
Ranorex.Form calcForm = "/form[@title='Calculator']";
Text textBox = "/form[@title='Calculator']/text[@controlid='403']";
calcForm.EnsureVisible();
            	
// Logs the current desktop view
Report.Screenshot();
Report.Screenshot(calcForm);
Report.Screenshot(textBox);

Report.End();

VB.NET

' Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", True)

' Get calculator application and one element
' just for screen shot report
Dim calcForm As Ranorex.Form = "/form[@title='Calculator']"
Dim textBox As Text = "/form[@title='Calculator']/text[@controlid='403']"
calcForm.EnsureVisible()

' Logs the current desktop view
Report.Screenshot()
Report.Screenshot(calcForm)
Report.Screenshot(textBox)

Report.End()

Python

# Setup Reporter
Report.Setup(ReportLevel.Debug, "myReport.rxlog", None)

# Get calculator application and one element
# just for screen shot report
calcForm = Form("/form[@title='Calculator']")
textBox = Text("/form[@title='Calculator']/text[@controlid='403']")
calcForm.EnsureVisible()

# Logs the current desktop view
Report.Screenshot()
Report.Screenshot(calcForm.Element)
Report.Screenshot(textBox.Element)

Report.End()
Report including screen shots

Specifying a user defined Style sheet

Setup user defined stylesheets to use your personal reporting layout before calling the Ranorex.Setup method as follows:

C#

// Set user defined stylesheet file
XmlLogger.SetReportStylesheetFile("userDefinedStylesheet.xsl");

// Setup reporting
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true);

VB.NET

' Set user defined stylesheet file
XmlLogger.SetReportStylesheetFile("userDefinedStylesheet.xsl")

' Setup reporting
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true)

Python

# Set user defined stylesheet file
XmlLogger.SetReportStylesheetFile("userDefinedStylesheet.xsl")

#/ Setup reporting
Report.Setup(ReportLevel.Debug, "myReport.rxlog", true)

Report within Ranorex Studio projects

When using Ranorex Studio all generated report files are automatically collected within the Reports folder.

C#

// Setup Reporter to default values
Report.SetupDefault();

VB.NET

' Setup Reporter to default values
Report.SetupDefault()

Python

# Setup Reporter to default values
Report.SetupDefault()
The method 'Report.SetupDefault' causes the reporter to use a log file name which consists of the project's name and a time stamp suffix.
Collected report files within Ranorex Studio project

Recorder based reports

After saving a recording to a specific file, the Recorder automatically creates a report file for each play event. The generated file name contains an additional time stamp and is located within the same folder as the recording file.