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 β
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 β
The project folder structure for the above test will be as follows β
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.
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
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
Pingback: Behave - Retry Mechanism - Adglob Infosystem Pvt Ltd
Pingback: kel-tec
Pingback: sahabat kartu