Steps to Develop a Reporting Module in a Test Automation Framework
In this tutorial for Creating a test automation framework with C#, Selenium 3 and Nunit, we’ll learn how to develop a reporting module so it will support the report deposition which will provide an indication on what failed, what passed and the specific point it occurred.
Class 1 – Creating an Automated Test Using Selenium WebDriver 3 and C#
Class 2 – How to Create a Test Automation Framework Architecture with Selenium WebDriver 3
Class 3 – Utilizing Test Automation Framework with Advanced Capabilities
It’s important for our test automation framework to have a reporting module for a number of reasons:
- Gives us an indication about the location of the failure.
- An ability to compare different executions, assuming something failed in the previous execution.
- Automation developers can send an execution report summary to the relevant R&D team for an indication about the progress of the tests.
The structure of the report will be a CSV document containing the following fields:
Let’s begin with creating a new class called ‘Reports’ and then we’ll paste the following code:
public class Reports
private string BrowserType;
private string url;
private DateTime date;
private FileStream fs;
private StringBuilder reportcsv;
private string filePath;
private string fileName;
public Reports(string BrowserType, string url)
this.BrowserType = BrowserType;
this.url = url;
date = DateTime.Now;
fileName = date.Date.Date.ToShortDateString() + date.TimeOfDay.Hours.ToString() + date.TimeOfDay.Minutes.ToString();
reportcsv = new StringBuilder();
filePath = @"C:\Users\TestProject\Desktop\Automation\" + fileName + ".csv";
private void createCsvFile()
public void addLine(string description, string result, string exception)
reportcsv.Append(description + ",");
reportcsv.Append(result + ",");
reportcsv.Append(exception + ",");
There are number of variables and functions:
The names of the variables ‘date’ and ‘url’ are going be a part of the report data.
The purpose of the class builder is to initialize the report details as the tested browser’s type, website’s url, test date eventually turning to the following function:
createCsvFile – This function creates the document of our report, and initializes it with the following headers:
- StepDescription – Desciption of step in test
- Pass/Fail – Result of the test run.
- Exception – If exception was thrown.
addLine – A function that adds a line to our report. The function receives the step’s description, the result and the expected result.
-Don’t hesitate to share your thoughts and testing stories.