How to generate reports in Behave-Python?
Asked Answered
C

6

7

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?

Clearsighted answered 23/11, 2016 at 11:19 Comment(0)
T
13

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.

Theft answered 10/7, 2017 at 12:53 Comment(2)
getting started with allure: docs.qameta.io/allure/#_installing_a_commandlineAssumpsit
@Theft - I want to save html allure generated report into some specific folder. is it possible?Cognoscenti
K
3

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.

Knife answered 16/12, 2018 at 13:39 Comment(0)
F
2

Behave can also generate reports in jUnit XML format. You can enable this feature simply by adding --junit to the commandline [1]. More info about formatters and reporters here [2].

$ behave --junit

[1] http://pythonhosted.org/behave/behave.html?highlight=#cmdoption--junit

[2] http://pythonhosted.org/behave/formatters.html

Folie answered 25/11, 2016 at 13:55 Comment(2)
On running multiple feature files, it would generate multiple XML files for each feature file and also with the XML file what conversion needs to be done to view in html format. Any plug-ins or tools needs to be added.Clearsighted
@Folie - your provided urls seems not working. can you please update answer?Cognoscenti
M
2

Because my automations which using behave are all running on Jenkins so I can use the Jenkins plugin to display my junit report.

I think this question might help you: How can I generate an HTML report for Junit results?

You can use your junit result from behave and follow some of the top answers in this question.

BTW, if you would like to use jenkins and if you need 'good-looking' html report of behave, I would suggust you to make behave generating json output for you and display the json output using reporter of cucumber.

Miser answered 28/11, 2016 at 22:3 Comment(5)
How to get json output in Behave framework when running multiple feature files.Clearsighted
simply use behave -f json -o path-to-your-output-file. It will test all your features and generate the json output for all of them. Also you can specify which features to run behave -f json -o path-to-your-output-file youfeature.featureMiser
once I got json file how to convert it as a html format which should be in a graphical type to view.Clearsighted
I think you can probably take a look at npmjs.com/package/cucumber-html-reporterMiser
Also I would like to suggust you to use jenkins since there are lots of plugins. Sorry I miss one thing, you should use something like github.com/behalfinc/b2c to convert behave json to cucumber json because there are much more great report tools for cucumer than behave. Hope this can help youMiser
D
0

Steps to generate allure report in Python behave framework.

  1. Install the allure

    pip install allure-behave

  2. Download the Allure exe file https://bintray.com/qameta/generic/allure2/2.6.0#files/io%2Fqameta%2Fallure%2Fallure%2F2.6.0

  3. Extract it and add the bin path into the environment variable(system variable path).

    C:\Users\arya\Downloads\allure-2.6.0\allure-2.6.0\bin

  4. Open cmd prompt and go where the xml report is present and give the below cmd.

    Type allure generate and give the path where your xml files are present.

    D:\automation\api\reports>allure generate D:\automation\api\reports

    Report successfully generated to allure-report

  5. Go to D:\automation\api\reports\allure-report and open the index.html file on Microsoft Edge browser.

Allure report is not working in Chrome or Firefox or IE browser.

Dragon answered 3/1, 2020 at 6:4 Comment(0)
W
0

To have the possibility of generaring execution reports in an easy way, we have implemented the following wrapper on top of Behave, called BehaveX, that not only generates reports in HTML format, but also in xml and json formats. It also allows us to execute tests in parallel and provides some additional features that simplify the implementation of agile practices: https://github.com/hrcorval/behavex

Westonwestover answered 19/5, 2022 at 11:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.