With the Excel Plug-In (Beta) it is now possible to automate the content of an Excel work sheet. This plug-in is not designed solely for getting data from Excel sheets (please read Data Driven Testing here), instead it offers you the opportunity to automate the cells, rows and columns of an Excel document. For example, if you want to validate the impacts of your add-on on Excel, then the Excel plug-in is definitely the correct tool for you. In addition to access to the Excel UI elements, there are also new adapters available:
Through these adapters it is also possible to interact with the objects provided by the Excel object model.
Set up the Excel Plug-In
We now create a new project, which will show briefly what’s possible with the new Excel Plug-In. In the example we perform a calculation (implemented in user code) and use one of the formulas (actions recorded by Ranorex Recorder) which should simulate an Add-On.

Adding the new reference
/// <summary>
/// Sets the values of the cell and carries out the calculation.
/// </summary>
/// <param name="sheet">The worksheet which should be used</param>
/// <param name="value">The calculate value</param>
/// <param name="resultCell">Your cell for the result</param>
/// <param name="cellNames">Your cells are filled with a value. For example '"A1",A2"'</param>
public static void SetValuesCalc(ExcelWorkSheet sheet, int value, string resultCell, params string[] cellNames)
{ int result= 0; Cell excelCell; foreach(string cell in cellNames) { //Searching for the cell excelCell = sheet.FindSingle<Cell>(".//cell[@address='" + cell +"']"); excelCell.Click(); //Enters the value by using the keyboard Keyboard.Press(value.ToString()); Keyboard.Press(Keys.Enter); //Calculates the result of all cells result= result+ Convert.ToInt32(excelCell.Text); } //Searching for the result cell excelCell = sheet.FindSingle(".//cell[@address='" + resultCell+ "']"); excelCell.Click(); //Uses the SUM Formula or Excel Keyboard.Press("=SUM(" + cellNames[0] + ":" + cellNames[cellNames.Length - 1] + ")"); Keyboard.Press(Keys.Enter); //Checks if the result of all cells equal the result cell. CheckResult(result, excelCell); }
CheckResult
/// <summary>
/// Checks the result of the calculation
/// </summary>
/// <param name="expectedResult">Result of all cells used</param>
/// <param name="result">The result cell of the calculation by Excel</param>
private static void CheckResult( int expectedResult, Cell result)
{ Validate.Attribute(result, "Text", expectedResult.ToString());
}

/*****************************************************
* Parameter 1: Path or element for excel sheet
* Parameter 2: Value shall be calculated.
* Parameter 3: The address of the result cell
* Parameter 4: The cell addresses which should have a value
* ***************************************************/
SimpleCalc.SetValuesCalc("/form[@processname='EXCEL']/element[@class='XLDESK']/workbook/table[@name='Sheet1']", 12, "A5", "A1","A2","A3");
Now we create a recording where we calculate the average value of several numbers and format the result. Thereby we show how easy it is to test an Excel Add-On with the Recorder.
//Execute recording Formula.Start();
You can download the sample project (Excel Project) which includes all the steps we performed in this blog. Please, don’t forget this Plug-In is still a Beta version and there is the possibility that some things might be changed.
Please send us your feedback and your suggestions to improve the Excel Plug-In.
Depending on the technology of your application under test, your controls may have dynamic identifiers. You could of course adapt the path for each repository item, but you would have to do this every time a new item is added. The RxPathWeights plug-in enables you to filter out those identifiers and use an even better attribute to identify your application under test.
Set up your RxPathWeights configuration file (Ext-JS example)Let’s assume we would like to automate a website which is built on the Ext JS framework (a cross-browser JavaScript library).
The picture below shows the RanoreXPath of an ext-js input field on following ext-js example page.
You can see containers in the path which are identified by the id, beginning with “ext-comp-” and ending with a numeric value. These ids are dynamically generated and they may change.
We would like to set up a filter mechanism which should eliminate id attributes beginning with “ext-gen” or “ext-comp-” and ending with a numeric value.

The configuration file consists of a rule element and an underlying condition element. The rule element enables you to change the weight of an attribute. By setting the weight to zero, the element will not be used in the RanoreXPath as an identifier anymore.
The condition element enables you to specify a rule for the attribute. In our sample, we would like to filter out ids which match following regular expression syntax
“(ext-gen|ext-comp-)[0-9]*”. (Read more about regular expression syntax here…)
<rxpathweights> <rule capability="webelement" attribute="id" setweight="0" conditionsoperator="or"> <condition source="self" attribute="id" match="(ext-gen|ext-comp-)[0-9]*" negate="false"/> </rule> </rxpathweights>
Save the config file and restart the Ranorex tools to load the RxPathWeights plug-in.
RxPathWeights plug-in documentationRole parameters:
Condition parameters:

There are many different possibilities for organizing a Ranorex Studio test automation project. The main goal when doing professional test automation with Ranorex is to create reusable automation modules. This can be realized by distinguishing between commonly used automation modules which perform actions like starting an application and specialized test modules performing a narrowly defined task.
The test project solution consists of:
Note: The important point is to separate execution and test case definition from the automation modules.
The executable project specifies the test cases of the solution and defines how each test case is triggered. Additionally, a ‘Setup’ method initializes the system under test (e.g. starting the application) while the ‘TearDown’ method cleans up the system be-fore the next test case is started (e.g. closing an application). Each test case is implemented within single files and classes:
The test case refers to the ‘AddVip’ recording which is part of the ‘VipTestLibrary’ DLL project. To reuse a method or class implemented within another project, a reference to the project has to be added.
Library Project - ‘VipTestLibrary’A library project can be created by adding a new project to the solution. The project template ‘Ranorex Class Library’ is part of the ‘Advanced’ folder shown within the ‘New Project’ dialog wizard.
The reason for having a Ranorex class library is to manage the modules (recordings or pure code based classes and methods) separated from the execution project. All recordings are stored within the ‘Recordings’ folder while the modules, totally based on user written code, are part of the ‘Code’ directory. Also the repository, which manages all the UI elements of the application under test, is part of the library project.
Common Class Library – ‘Common’It’s not required to have an additional library implemented to handle common methods like starting or closing the system under test. Regardless, when thinking about other test projects or solutions which require a common method like killing a process in order to shut down an application in cases of errors, it would be good to have one robust mechanism for that purpose. In comparison to the ‘VipTestLibrary’, the ‘Common’ class library project does not have any information about the application under test. Everything required for UI automation is provided by parameters.
Add the ‘Common’ library as reference in order to reuse the classes and methods implemented within it.
Test Case ExecutionIn that example the execution is triggered by a simple batch file, which specifies the execution sequence:
cd bin\debug call execution.exe -tc addsinglevip call execution.exe -tc savevip call execution.exe -tc connecttodatabase
It’s possible to evaluate the return values (FAIL=-1, SUCCESS=0) at the command line interface as well. In addition a command line based execution is supported by many test management tools. That helps to ease integration of Ranorex tests into existing execution environments.
Download the Ranorex Studio solution “VIP Test Solution” here.
When you run your daily user interface tests, the key point is to review the results of the individual tests. You want to know which tests succeeded and which failed, and maybe want to be notified of the results. Additionally, you might want the style of the reports to match the corporate identity design. Ranorex provides you with a flexible and customizable reporting engine that you can adapt to fit your needs.
This blog shows you how to:
You can easily customize the default Ranorex XML report by providing a new style sheet that is used to format the plain XML logging data to an HTML page. For example, by adding following XSL code to the default “RanorexReport.xsl” style sheet you get a summary heading at the top of the report page:
<h2>Summary: <xsl:choose> <xsl:when test="//message[@level='FAILED' or @level='ERROR']"> <span class="failure">FAILED</span> </xsl:when> <xsl:otherwise> <span class="success">PASSED</span> </xsl:otherwise> </xsl:choose> </h2>
In order to use the custom style sheet you have to add following line of code in your Ranorex code before the call to Report.Setup:
// set a custom stylesheet for the default XML report
XmlLogger.SetReportStylesheetFile("CustomStylesheet.xsl"); // append to an existing file with the same name
Report.Setup(ReportLevel.Info, logFileName, true);

In the same way you can edit the style sheet to match your corporate identity design. The above report also shows how to add plain HTML to the report, e.g. adding a link to www.ranorex.com:
// add some custom HTML message to the XML report Report.LogHtml(ReportLevel.Info, "Link", "<a href='http://www.ranorex.com/'>Visit www.ranorex.com!</a>");
For a detailed description on how to use the Ranorex reporting see the corresponding Ranorex User Guide section:
http://www.ranorex.com/support/user-guide-20/reporting-logging.html
For an instruction on how to add additional data to the default XML report see the following forum post:
http://www.ranorex.com/forum/report-appending-in-2-2-t1101.html#p5043
In order to store Ranorex reports to a database or send them by email, you have to create a custom logger class and attach it to the Ranorex report engine. This logger class has to implement the Ranorex.Core.IReportLogger interface that defines methods called by the report engine. Basically, there are four methods that you have to implement:
For demonstration purposes I will show you how send reports via email. We start by adding a new class MailLogger that implements the IReportLogger interface:
public class MailLogger : IReportLogger
{
}
If you use Ranorex Studio, you can right click on IReportLogger and select “MailLogger -> Implement Interface (implicit) -> IReportLogger” and Ranorex Studio will create stubs for the interface methods for you. In the constructor of our new class we create a new MailMessage that is sent when the report is finished, i.e. when the End method is called:
public MailLogger(string from, string to, string subject)
{ mail = new MailMessage(from, to); mail.Subject = subject;
}
public void End()
{ try { SmtpClient smtpClient = new SmtpClient(Host, Port); smtpClient.Send(mail); } catch (Exception ex) { Console.WriteLine(ex); }
}
The actual storing of report messages to the email is done in the LogText method, where we format the arguments by the report engine and store the formatted string to the email body:
public void LogText(ReportLevel level, string category, string message, bool escape)
{ mail.Body += string.Format("[{0}][{1, -7}][{2}]: {3}n", GetTimeStamp(), level, category, message);
}
The last thing we have to do is create a new instance of our MailLogger class and attach it to the Ranorex report engine. This code needs to be placed before or right after the call to Report.Setup, typically in the Main method (in the Program.cs file) of your application:
MailLogger mailLogger = new MailLogger("from@domain.com", "to@domain.com", "Ranorex Report for CustomLogging");
Report.AttachLogger(mailLogger);
Don’t forget to set the MailLogger.Host property to the host name of your SMTP server:
MailLogger.Host = "yourSmtpServer";
When you run the test, additionally to the standard XML and console reports you will get a report sent via email:

Report sent via email
SummaryThe Ranorex report engine allows you to customize the existing XML/HTML based reports as well as create your own reporting mechanism by implementing the IReportLogger interface. In this blog I demonstrated how to use a custom XSL style sheet to add a summary to the default XML report and how to send reports via email. Download the complete project containing the MailLogger class and the customized XSL style sheet using the following link:
Ranorex Studio project illustrating report customizing (including HTML MailLogger and custom XSL style sheet)
UPDATE: The MailLogger class in the project above now creates HTML emails, too!
If you have any questions or suggestions, please don’t hesitate to post your comments to this blog!
