logo logo

Develop a Reporting Module in a Test Automation Framework

Report Module in a Testing 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.

Tutorial Overview:

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:

  1. Gives us an indication about the location of the failure.
  2. An ability to compare different executions, assuming something failed in the previous execution.
  3. 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:

  • StepDescription
  • Pass/Fail
  • Exception

Let’s begin with creating a new class called ‘Reports’ and then we’ll paste the following code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
    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()
            File.AppendAllText(filePath, reportcsv.ToString());
        public void addLine(string description, string result, string exception)
            reportcsv.Append(description + ",");
            reportcsv.Append(result + ",");
            reportcsv.Append(exception + ",");
            File.WriteAllText(filePath, reportcsv.ToString());

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.

After creating the reporting module, continue to the Next tutorial to Start implementing the reporting class in our test automation framework.

-Don’t hesitate to share your thoughts and testing stories.


About the author

Asya Galinsky


7 2 comments

Leave a Reply