Skip to content
Go back

Test Automation - How To Add Git Version Control Data To Allure Report in Python

Published:

Introduction

In this article, I will review the ability to add Git version control data into our test automation report.

The technological stack used to implement the solution is:

Programing language: Python

Testing Framework: pytest

Reporting Framework: Allure

link to the project that was developed together with Elias Shourosh.

Sometimes passing tests becomes flaky, this can happen for many reasons:

There are, of course, more reasons, and we need a way to get all the relevant information into our reporting system to debug these reasons, and an important piece of the puzzle is our version control data.

The Solution – Adding version control data into Allure report

Allure reporting framework review

First, let’s review the allure framework.Here is a demo of the framework capabilities:https://demo.qameta.io/allure/

Why did we choose Allure?

The feature that we will use in this article to add our version control data is the ability to add environment information into the report.

Implementing the Solution

No alt text provided for this image

This first part consists of the AllureEnvironmentParser class, which has the write_to_allure_env method. A constructor specifies the file name of the XML file that will contain the data to be written. It writes key-value pairs separated by newlines from a dictionary to an XML file.

No alt text provided for this image

Second, the write_allure_environment fixture uses the GitPython library to access Git repository information and write it to the XML file. The AllureEnvironmentParser class writes information about the current commit, such as commit ID, author name, commit message, and commit date, to the XML file. This is after other fixtures have finished executing. In addition, it appends the browser version, base URL, and active branch name to the XML file.

The outcome of the run in the generated report is located under the environment section:

No alt text provided for this image

In conclusion

In this article, we reviewed the problem we were facing when needing to debug failing tests and not knowing the version control data of our automation code, then implemented a solution for adding the version control data directly to our reporting framework.

Happy testing!


Suggest Changes

Have a challenge? Let's Talk


Previous Post
Solving the JDK 17 Compatibility Issue with Appium: A Step-by-Step Guide
Next Post
Test Automation - How To Attach Session Storage, Local Storage, Cookies, and Console logs To Allure Report in Selenium Python