Customized Test Automation PDF Report


Generating Customized Test Automation PDF report is a great value add to your team. Let’s say for instance if you wish to share a high-level automation test report with your business stakeholders. Then emailing the report as a PDF is a simple and viable solution. However, sending predefined report or technical information is insignificant and uninteresting to the business. As a software testing services company, we use different report templates for different audiences. In this blog article, you will learn how to create Customized Automation Testing report using Behave & Python.

PDF Report Package Installation

For Windows users: If you see OSError: dlopen() failed to load a library: cairo / cairo-2, then you need to install GTK+. Refer the following URL for more details – Install GTK+ with the aid of MSYS2

Generating Behave JSON Outputs

In this blog article, we are using behave framework JSON output to create PDF report. To create JSON report from behave, use the below command.

Consuming the JSON Output

Create a python file and paste the below code.

Code Explanation

Line #1 & #2 – Package Imports

Line #3 – Opening the json output file which is generated by behave framework.

Line #4 – Loading the json file

Line #5 – Calling pug_to_html method to generate the PDF report.

Note – To generate the report, you need template.pug file. Please refer the pug_to_html method call, you can see template.pug file as one of the arguments.

Template.pug file

Pug is a template engine. The PDF_Reports package uses Pug to generate the PDF output. Let’s see how to create the template file in your project.

1) File Creation – Create & open template.pug file in your project

2) Report title – The below line creates an H1 tag and applies Semantic UI CSS.

3) Sidebar – Creating sidebar in the report which enhances the look and feel.

4) Iterate features from the json data

5) Iterate Scenarios

6) Iterate Steps

7) Run the python file which is calling pug_to_html method. If the report is generated successfully, you can see the ouput as shown below.

Customized Test Automation PDF Report

Full Code

In ConclusionThe above template is ( quite simple / very straightforward,) it does not have implementation to handle BDD Scenario Outline, Tags, and Screenshots. As an automation testing company, we use comprehensive Pug reporting template to generate PDF reports. Once the template is in place, you can create multiple reports for different audiences. For successful test automation, make your reports easily accessible to everyone in the team.


Leave a Reply

Your email address will not be published. Required fields are marked *