Behave – Reports

Behave - Reports

Behave Reports generation is one of the most important steps towards the test automation framework. At the end of the execution, we cannot rely on the console output rather we should have a detailed report.

It should have the information on the count of tests that passed, failed, skipped feature, and scenario breakdown. Behave does not produce an in-built report but it can output in multiple formats and we can utilize the third-party tools to generate a report.

All the available formatters in Behave are displayed with the command βˆ’

behave --format help

When you use the command, the following screen will appear on your computer βˆ’

Behave - Reports

Some of the common Behave reports are βˆ’

  • Allure Report.
  • Output JSON Report.
  • JUnit Report

Common Behave reports –

JUnit Report

Let us execute a test having two feature files with the below test results βˆ’

Behave - Reports

The project folder structure for the above test will be as follows βˆ’

Behave - Reports

Step 1 βˆ’ Execute the command

To create a JUnit report, run the command given below βˆ’

behave --junit 

Step 2 βˆ’ Report folder generation

A folder called theΒ reportsΒ gets generated within the project, having the nameΒ TESTS-<feature file name>.xml.

Behave - Reports

Here, Payment and Payment1 are the names of the feature files.

Step 3 βˆ’ Report generation to a specific folder

To generate the reports to a specific folder, say my_reports. We have to run the below-mentioned command βˆ’

behave --junit --junit-directory my_reports
Behave - Reports

A folder called the my_reports gets generated within the project which contains the reports.

JSON Report

We can create the Behave JSON report. The JSON is actually a formatter.

Let us execute a test having two feature files with the below test results βˆ’

The project folder structure for the above test is as follows βˆ’

Step 1 βˆ’ Execute the command

To create a JSON output in the console, run the command βˆ’

behave -f json

The following screen will appear βˆ’

Step 2 βˆ’ Output in a readable format

To create a JSON output in a more readable format, run the following command βˆ’

behave -f json.pretty

Some portion of the output captured in the below image βˆ’

Step 3 βˆ’ Report generation to a specific folder

To generate the reports to a specific folder say, my_reports.json, we have to run the following command βˆ’

behave –f json.pretty –o my_reports.json

The following image represents the screen that will appear on your computer.

A folder called the my_reports.json gets generated within the project, having details of all the features which are executed.

Allure Report

To generate Allure reports in Behave, first, we have to install Allure in the system. For installation from the command line in Linux, run the following commands one after the other βˆ’

sudo apt-add-repository ppa:qameta/allure
sudo apt-get update
sudo apt-get install allure

For Mac users, installation is done with the Homebrew with the following command βˆ’

brew install allure

For Windows, Allure is installed from the Scoop installer. Run the below command to download and install Scoop and finally, execute it in the PowerShell βˆ’

scoop install allure

To update Allure distribution installations from Scoop, run the below command from the installation directory of Scoop βˆ’

\bin\checkver.ps1 allure -u

Finally, run the command given below βˆ’

scoop update allure

After Allure installed Python. For this, run the following command βˆ’

pip install allure-behave

To verify if Allure has been installed successfully, run the command stated below βˆ’

allure

Let us execute a test having two feature files with the below test results βˆ’

The project folder structure for the above test is as follows βˆ’

Step 1 βˆ’ Report generation to a specific folder

To generate the reports to a specific folder, say my_allure, we have to run the following command βˆ’

behave -f allure_behave.formatter:AllureFormatter –o my_allure

You will get the screen as shown below βˆ’

A folder called the my_allure gets with a .json extension.

Step 2 βˆ’ Start the webserver

To start the webserver, run the command given below βˆ’

allure serve my_allure

Here, the my_allure is the directory that contains the allure JSON files.

Simultaneously, a browser gets opened, with the Allure report as shown below βˆ’

We can also click on individual features and find their breakdowns, as shown below βˆ’

Next Topic – Click Here

This Post Has 3 Comments

Leave a Reply