ElkanRoelen / behatformatter

Behat 3 Twig formatter
Other
17 stars 17 forks source link

BehatFormatter

Behat 3 extension for generating AWESOME reports from your test results.

Latest Stable Version Total Downloads Latest Unstable Version License

Twig report

Live demo available at: http://www.bug-hunter.nl/testreport/index.html (daily generated)

Twig Screenshot

Features

It's easy!!

Installation

Prerequisites

This extension requires:

Through composer

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

Install with composer:

$ composer require --dev elkan/behatformatter

Install using composer.json

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

{
    "require": {
        "behat/behat": "3.*@stable",
        "elkan/behatformatter": "v1.0.*",
    },
    "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/

  extensions:
    elkan\BehatFormatter\BehatFormatterExtension:
      projectName: BehatTest
      name: html
      renderer: Twig,Behat2
      file_name: Index
      print_args: true
      print_outp: true
      loop_break: true
      show_tags: true

Configuration

Screenshots

To generate screenshots in your testreport you have to change your FeatureContext.php:

From:

# FeatureContext.php
class FeatureContext extends MinkContext
{
...
}

To:

# FeatureContext.php
class FeatureContext extends elkan\BehatFormatter\Context\BehatFormatterContext
{
...
}

Extra function: Placeholders

It is possible to use placeholders in feature steps. Add a BeforeStep, BeforeScenario or BeforeSuite action to your context file containing a setTransformValues() action. You can add custom placeholders by using an array.

example context rules:

    /**
     * @BeforeScenario
     */
    public function createTransformValues(){
        $this->setTransformValues(array(
            "<test>" => "A simple test value",
            "<timestamp>" => time()
        ));
    }

Example feature:

  @test
  Scenario: Sign up for the newsletter
    When I fill in "email" with "test+<timestamp>+behat@bug-hunter.nl"
    And I press "Sign up"

Example Output:

  @test
  Scenario: Sign up for the newsletter
    When I fill in "email" with "test+1461777849+behat@bug-hunter.nl"
    And I press "Sign up"

Todo:

License and Authors

Authors: https://github.com/ElkanRoelen/BehatFormatter/graphs/contributors