Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate reports in Behave-Python?

For Java there are external report generation tools like extent-report,testNG. The Junit produces the xml format output for individual feature file. To get a detailed report, I don't see an option or wide approach or solution within the Behave framework.

How to produce the reports in Behave, do any other tools or framework needs to be added for the report generation in Behave?

like image 960
Ashok kumar Ganesan Avatar asked Nov 23 '16 11:11

Ashok kumar Ganesan


2 Answers

You can generate Allure report for your Behave tests.

First you need to install Allure Behave formatter:

$ pip install allure-behave

Then specify the formatter when run your tests:

$ behave -f allure_behave.formatter:AllureFormatter -o %allure_result_folder% ./features

This will generate JSON report to %allure_result_folder%. Then, to view HTML report you can use Allure Command line (plugins for Jenkins/TeamCity/Bamboo also available)

$ allure serve %allure_result_folder%

For more details about Allure report you can see the docs.

like image 62
thistle Avatar answered Sep 18 '22 11:09

thistle


I know this question was asked/answered quite sometime ago.

But I thought of giving the solution which worked for me.

The Cucumber json schema differs from Behave ones. So you can't use the json created by behave to generate html reports using Cucumber Reports plugin. When I tried behave json with cucumber reports, this is what I got and you would also see NPE for uri since cucumber json was expecting to have uri exists but the behave json doesn't have uri hence NPE.

`[CucumberReport] Processing 1 json files: 
 [CucumberReport] /var/lib/jenkins/jobs/behave-test/builds/14/cucumber-html- 
                  reports/.cache/results.json
 [CucumberReport] Missing report result - report was not successfully completed
 [CucumberReport] Build status is left unchanged`

You would see report was not successfully completed.

So I installed behave2cucumber to convert behave json into cucumber json.

pip install behave2cucumber

Then have an additional step like below.

python -m behave2cucumber -i behave_json.json -o cucumber_json.json

-i represents input file in our case json file generated by behave

-o represents output file in our case cucumber compatible json file

cucumber_json.json would have the uri field populated which were missing behave json.

It works like charm.

Hope it helps.

like image 26
Thayz Avatar answered Sep 16 '22 11:09

Thayz