Ranorex

English|Deutsch

Logging & Validation

print friendly page

This document describes the usage of the Ranorex Logger in C# and how it works with a simple calculator program.

Using the Ranorex Logger

First, you have to initialize the Ranorex Logger.

The Ranorex Logger supports the following output formats:

  • Console text
  • Text file
  • XML file

The destination paths for the logging outputs can be set in the initialize method. Additionally, you have to set the minimal log level for the output messages.

C#

Logger.Initialize(true, "test.txt", "test.xml", LogLevel.Info);

VB.NET

Logger.Initialize(True, "test.txt", "test.xml", LogLevel.Info)

Note: To use the XML logger file, the RxLog.xsl (which can be found under Bin/RxLog.xsl) must be in the same directory.

After that, you can call the logging routines.

There are 4 different levels for logging:

  • Debug
  • Information
  • Warning
  • Error

C#

Logger.Debug("User", "Send keystrokes 'calc.exe'.");
Logger.Info("User", "Find child by control id '304'.");
Logger.Warn("User", "No Parameter set, using default value.");
Logger.Error("User", "Button 'w' couldn't be found.");

VB.NET

Logger.Debug("User", "Send keystrokes 'calc.exe'.")
Logger.Info("User", "Find child by control id '304'.")
Logger.Warn("User", "No Parameter set, using default value.")
Logger.Error("User", "Button 'w' couldn't be found.")

Finally, close the Ranorex Logging Facility with:

C#

Logger.Close();
// open logging output
Logger.OpenLogViewer();

VB.NET


Logger.Close()
' open logging output
Logger.OpenLogViewer

Logging output of the test application

The following screenshots show the output of the Ranorex Logger based on a test application that performs a simple calculation to test the various logging functions.

How to use the Ranorex Validation class

The Ranorex Validation class supports the implementation of checkpoints and automates the generation of a better test report. The Validation offers a set of methods to check standard conditions as well as direct validation like 'HasText' or 'IsVisible'.

All methods provide at least one overload to determine whether a false condition or a failed check signals an error.

Following code validates every step of a calculator automation and logs the validation report automatically.

C#

System.Diagnostics.Process.Start("calc.exe");
Logger.Initialize(true, "test.txt", "test.xml", LogLevel.Info);
Form calc = Application.FindFormTitle("Calculator", SearchMatchMode.MatchExact,true,5000);
Validate.IsTrue(calc!=null,"Search for 'Calculator' application");
				
Control buttonFive = calc.FindControlId(129);
Validate.IsTrue(buttonFive!=null,"Search button '5'");
Validate.HasText(buttonFive,"5", "Check button text");
Mouse.ClickControl(buttonFive);
				
Control buttonAdd = calc.FindControlId(92);
Validate.IsTrue(buttonAdd!=null,"Search button '+'");
Validate.HasText(buttonAdd,"+", "Check button text");
Mouse.ClickControl(buttonAdd);
				
// ... clicking and validating other buttons
				
Control textBox = calc.FindTextBox(403);
Validate.HasText(textBox, new Regex("^7"),"Check calculator output", true);
Logger.OpenLogViewer();

VB.NET

Logger.Initialize(true, "test.txt", "test.xml", LogLevel.Info)
System.Diagnostics.Process.Start("calc.exe")
Dim calc As Form = Application.FindFormTitle("Calculator", SearchMatchMode.MatchExact, True, 5000)
Validate.IsTrue(calc IsNot Nothing, "Search for 'Calculator' application")

Dim buttonFive As Control = calc.FindControlId(129)
Validate.IsTrue(buttonFive IsNot Nothing, "Search button '5'")
Validate.HasText(buttonFive, "5", "Check button text")
Mouse.ClickControl(buttonFive)

Dim buttonAdd As Control = calc.FindControlId(92)
Validate.IsTrue(buttonAdd IsNot Nothing, "Search button '+'")
Validate.HasText(buttonAdd, "+", "Check button text")
Mouse.ClickControl(buttonAdd)

' ... clicking and validating other buttons
Dim textBox As Control = calc.FindTextBox(403)
Validate.HasText(textBox, New Regex("^7"), "Check calculator output", True)
Logger.OpenLogViewer()
Each validation produces a logger output automatically and signals with green background color a successful passed validation check point.
All validation checks passed successfully.
Only one validation failed. A warning was logged.
A required validation failed. The test was aborted.