
This document describes the usage of the Ranorex Logger in C# and how it works with a simple calculator program.
First, you have to initialize the Ranorex Logger.
The Ranorex Logger supports the following output formats:
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.
Logger.Initialize(true, "test.txt", "test.xml", LogLevel.Info);
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:
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.");
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:
Logger.Close(); // open logging output Logger.OpenLogViewer();
Logger.Close() ' open logging output Logger.OpenLogViewer
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.
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.
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();
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()
Announcements