roydude/behat-html-formatter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

roydude/behat-html-formatter

最新稳定版本:v0.1.0

Composer 安装命令:

composer require roydude/behat-html-formatter

包简介

Creates an HTML report for Behat tests (enhanced version of emuse/behat-html-formatter)

README 文档

README

Behat 3 extension for generating HTML reports from your test results (custom version of the original from emuse: https://github.com/dutchiexl/BehatHtmlFormatterPlugin). The changes I have made only relate to the Twig report (see below).

Latest Stable Version Total Downloads Latest Unstable Version License

Twig report

Twig Screenshot Twig Screenshot

How?

  • The tool can be installed easily with composer.
  • Defining the formatter in the behat.yml file
  • Modifying the settings in the behat.ymlfile

Installation

Prerequisites

This extension requires:

  • PHP 5.3.x or higher
  • Behat 3.x or higher

Through composer

The easiest way to keep your suite updated is to use Composer:

Install with composer:

$ composer require --dev roydude/behat-html-formatter

Install using composer.json

Add BehatHtmlFormatterPlugin to the list of dependencies inside your composer.json.

{
    "require": {
        "behat/behat": "3.*@stable",
        "roydude/behat-html-formatter": "0.1.*",
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}

Then simply install it with composer:

$ composer install --dev --prefer-dist

You can read more about Composer on its official webpage.

Basic usage

Activate the extension by specifying its class in your behat.yml:

# behat.yml
default:
  suites:
    ... # All your awesome suites come here

  formatters:
    html:
      output_path: %paths.base%/build/html/behat

  extensions:
    roydude\BehatHTMLFormatter\BehatHTMLFormatterExtension:
      name: html
      renderer: Twig
      file_name: index
      print_args: true
      print_outp: true
      loop_break: true

Configuration

  • Makeing (noreport) part of a test suit name will mean it's excuded from the report (handy for cache tests, for example, which aren't so interesting to business users who read the report).
  • output_path - The location where Behat will save the HTML reports. The path defined here is relative to %paths.base% and, when omitted, will be default set to the same path.
  • renderer - The engine that Behat will use for rendering, thus the types of report format Behat should output (multiple report formats are allowed, separate them by commas). Allowed values are:
  • Twig A new and modern report format based on Twig.
  • file_name - (Optional) Behat will use a fixed filename and overwrite the same file after each build. By default, Behat will create a new HTML file using a random name ("renderer name"_"date hour").
  • print_args - (Optional) If set to true, Behat will add all arguments for each step to the report. (E.g. Tables).
  • print_outp - (Optional) If set to true, Behat will add the output of each step to the report. (E.g. Exceptions).
  • loop_break - (Optional) If set to true, Behat will add a separating break line after each execution when printing Scenario Outlines.

Blocked tests

To mark a test as skipped make sure it exits with PendingExcpetion, i.e.:

throw new PendingException ("This scenario is blocked by bug MYPROJ-101");

Screenshot

The facility exists to embed a screenshot into test failures.

Currently png is the only supported image format.

In order to embed a screenshot, you will need to take a screenshot using your favourite webdriver and store it in the following filepath format:

results/html/assets/screenshots/{{feature_name}}/{{scenario_name}}.png

The feature_name and scenario_name variables will need to be the relevant item names without spaces.

Below is an example of FeatureContext methods which will produce an image file in the above format:

        /**
         * @BeforeScenario
         *
         * @param BeforeScenarioScope $scope
         *
         */
        public function setUpTestEnvironment($scope)
        {
            $this->currentScenario = $scope->getScenario();
        }

        /**
         * @AfterStep
         *
         * @param AfterStepScope $scope
         */
        public function afterStep($scope)
        {
            //if test has failed, and is not an api test, get screenshot
            if(!$scope->getTestResult()->isPassed())
            {
                //create filename string
                $featureFolder = str_replace(' ', '', $scope->getFeature()->getTitle());

                $scenarioName = $this->currentScenario->getTitle();
                $fileName = str_replace(' ', '', $scenarioName) . '.png';

                //create screenshots directory if it doesn't exist
                if (!file_exists('results/html/assets/screenshots/' . $featureFolder)) {
                    mkdir('results/html/assets/screenshots/' . $featureFolder);
                }

                //take screenshot and save as the previously defined filename
                $this->driver->takeScreenshot('results/html/assets/screenshots/' . $featureFolder . '/' . $fileName);
            }
        }

Note that the currentScenario variable will need to be at class level and generated in the @BeforeScenario method as Behat does not currently support obtaining the current Scenario in the @AfterStep method, where the screenshot is generated

Issue Submission

When you need additional support or you discover something strange, feel free to Create a new issue.

License and Authors

Authors: https://github.com/roydude/BehatHtmlFormatterPlugin/contributors

To do

  • Consider adding buttons for Skipped and Undefined.
  • Simplify screenshots.

统计信息

  • 总下载量: 15.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 117
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-08-04