Package: behave-html-pretty-formatter
HTML Pretty formatter for BehaveInspired byjest-html-reporterUsing projectdominateto generate the pageInstallationpython3-mpipinstallbehave-html-pretty-formatterUsageTo use it with Behave create abehave.inifile in your project folder
(or in home) with the following content:# -- FILE: behave.ini# Define ALIAS for PrettyHTMLFormatter.[behave.formatters]html-pretty=behave_html_pretty_formatter:PrettyHTMLFormatter# Optional configuration of PrettyHTMLFormatter# also possible to use "behave ... -D behave.formatter.html-pretty.{setting}={value}".[behave.userdata]behave.formatter.html-pretty.title_string=Test Suite Reporter# Example usecase, print {before/after}_scenarios as steps with attached data.behave.formatter.html-pretty.pseudo_steps=false# Structure of the result html page readable(pretty) or condensed.behave.formatter.html-pretty.pretty_output=true# The '%' must be escaped in ini format.behave.formatter.html-pretty.date_format=%%d-%%m-%%Y %%H:%%M:%%S# Defines if the summary is expanded upon start.behave.formatter.html-pretty.show_summary=false# Defines if the user is interested in what steps are not executed.behave.formatter.html-pretty.show_unexecuted_steps=true# Define what to collapse by default, possible values:#  "auto" - show everything except embeds (default)#  "all" - hide everything#  comma separated list - specify subset of "scenario,embed,table,text"#  "none" - show everything, even embedsbehave.formatter.html-pretty.collapse=auto# Defines if the user wants to see previous attempts when using auto retry.# Auto retry https://github.com/behave/behave/blob/main/behave/contrib/scenario_autoretry.pybehave.formatter.html-pretty.show_retry_attempts=true# Override global summary visibility#  "auto" - show global summary if more than one feature executed (default)#  "true" - show global summary#  "false" - hide global summarybehave.formatter.html-pretty.global_summary=auto# Following will be formatted in summary section as "tester: worker1".behave.additional-info.tester=super_worker# Can be used multiple times.behave.additional-info.location=super_awesome_labAlternatively, with behave >= v1.2.7.dev3, you can put the same configuration inpyproject.toml, like so:[tool.behave.formatters]"html-pretty"="behave_html_pretty_formatter:PrettyHTMLFormatter"# Optional configuration of PrettyHTMLFormatter[tool.behave.userdata]"behave.formatter.html-pretty.title_string"="Test Suite Reporter""behave.formatter.html-pretty.pseudo_steps"=false"behave.formatter.html-pretty.pretty_output"=true"behave.formatter.html-pretty.date_format"="%%d-%%m-%%Y %%H:%%M:%%S""behave.formatter.html-pretty.show_summary"=false"behave.formatter.html-pretty.collapse"="auto""behave.formatter.html-pretty.show_unexecuted_steps"=true"behave.formatter.html-pretty.global_summary"="auto""behave.additional-info.tester"="super_worker""behave.additional-info.location"="super_awesome_lab"Then use the formatter by running Behave with the-f/--formatoption, e.g.behave -f helpbehave -f html-prettybehave -f html-pretty -o behave-report.htmlYou can find information about behave and user-defined formatters in thebehave docs.HTML Pretty has High contrast optionDefault Static Example:High contrast Static Example:Colours adjusted.Extra information is added before every decorator about the status of the step.Text is bigger.You can switch between the different contrasts with the toggle button.Dark modeStylesheet follows the browser dark theme, so it reverts background to dark and
adjusts colors to darker shade.Summary is hidden by defaultPretty HTML Formatter With Summary Expanded and Collapsed Steps:Pretty HTML Formatter High contrast With Summary Expanded and Collapsed Steps:To change the setting use the .ini file.behave.formatter.html-pretty.show_summary = trueHACKINGMIME TypesTake a look at theCommon MIME types, few of them are useful for us.Encoding to base64data_base64=base64.b64encode(open("/path/to/image","rb").read())data_encoded=data_base64.decode("utf-8").replace("\n","")Format in which the data is inserted to the html# Format"data:<mime_type>;<encoding>,<data_encoded>"# Examplef"data:image/png;base64,{data_encoded}"Defined functions you can useBasic setup for using formatter functionsforformatterincontext._runner.formatters:ifformatter.name=="html-pretty":context.formatter=formatterSet Iconicon_data=f"data:image/svg+xml;base64,{data_encoded}"context.formatter.set_icon(icon=icon_data)Example use case - an indicator if the test is running under X11 or Wayland:Set Title for the HTML pagecontext.formatter.set_title(title="Test Suite Reporter")This is configurable also from the behave.ini filebehave.formatter.html-pretty.title_string = Test Suite ReporterCommentary step in HTML reportUsed as an information panel to describe or provide infomation about the page contents.
You will need to define your own step where you will set flag for commentary step.@step('Commentary')defcommentary_step(context):# Get the correct step to override.scenario=context.formatter.current_scenariostep=scenario.current_step# Override the step, this will prevent the decorator to be generated and only the text will show.step.commentary_override=TrueFeature file example usage:@commentaryScenario:Example of commentary usage.*Start application "zenity" via command "zenity --about"*Commentary"""This field is generated from decorator 'Commentary'Where you insert text and override step to not print its decorator.The text will get printed and will be seen, as you can see, haha."""*Left click "About" "radio button"Result can be seen in the image examples.Embedding data to the reportBasic embedding setup - save embedding function to contextforformatterincontext._runner.formatters:ifformatter.name=="html-pretty":context.embed=formatter.embed# Not required if you already have the Basic setup.# You would than use: 'context.formatter.embed' instead of 'context.embed'Embed imagecontext.embed(mime_type="image/png",data="/path/to/image.png",caption="Screenshot")Embed videocontext.embed(mime_type="video/webm",data="/path/to/video.webm",caption="Video")Image and Video examples:Defined MIME types and corresponding accepted dataThese are examples we use on daily basis, we can define more if required.mime_type="video/webm",data="/path/to/video.webm"ordata="<base64_encoded_video>"mime_type="image/png",data="/path/to/image.png"ordata="<base64_encoded_image>"mime_type="text/plain",data="<string>"mime_type="text/html",data="<string>"# data string is pasted as raw HTML (not escaped)mime_type="text/markdown",data="<string>"# data string is converted using markdown pip modulemime_type="link",data="list(<link>, <label>)"You can simply setdata=data_encodedgenerated as described inEncoding to base64section and the formatter will generate the properFormatbased on MIME type or you can just use thedata="/path/to/file"and formatter will attempt to convert it.Functionembed()returns object, which can be saved and modified later viaset_data()andset_fail_only()methods. This is if you want to embed some data which are still being processes (output of a backgroud process started in a step, etc.).Pseudo stepsIf the testsuite usesbefore_scenario()andafter_scenario()and you would like to see them as steps in HTML report (for example to have embeds separated from the standard steps), configuration switch in behave.ini filebehave.formatter.html-pretty.pseudo_steps = truewill do the trick, together with callingcontext.html_formatter.before_scenario_finish(status)at the end ofbefore_scenario()(analogously forafter_scenario()). The status is one of"passed", "failed", "skipped". Function will set color class of the pseudo step and also record pseudo step duration.# Example use in features.environment.pydefbefore_scenario(context,scenario):...# This requires to have html_formatter set by code above.iferror_found:context.embed("text",str(error_found),"Error Message")context.html_formatter.before_scenario_finish("failed")raiseerror_foundelse:context.html_formatter.before_scenario_finish("passed")defafter_scenario(context,scenario):...iferror_found:context.embed("text",str(error_found),"Error Message")context.html_formatter.after_scenario_finish("failed")raiseerror_foundelse:context.html_formatter.after_scenario_finish("passed")ContributingYou want to help with improving this software? Please create an issue in our open bug tracker, or open a pull request directly.We usetoxfor running linting and tests, e.g.toxtox -ltox -e flake8For code formatting we useblack, which you can run using our Tox setup, e.g.tox -e blackIf you need to change CSS or JavaScript code: First edit the regular files, then generate the minified versions like so:tox -e minifyImage ExamplesPretty HTML FormatterPretty HTML Formatter High ContrastPretty HTML Formatter With Summary Expanded and Collapsed StepsPretty HTML Formatter High Contrast with Summary Expanded and Collapsed Steps