Skip to content

Commit

Permalink
behat3 (via #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tikolakin authored and baev committed Sep 25, 2018
1 parent 7f7a8a1 commit ae42eb3
Show file tree
Hide file tree
Showing 10 changed files with 1,367 additions and 478 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*.{php,md}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Apache License
==============

Copyright 2016 Eduard Sukharev <[email protected]>
Copyright 2018 Tiko Lakin <[email protected]>

_Version 2.0, January 2004_
_&lt;<http://www.apache.org/licenses/>&gt;_
Expand Down
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,47 @@ To install using [Composer](https://getcomposer.org/) simply add `"allure-framew
...
"require": {
...
"allure-framework/allure-behat": "~1.0.0",
"allure-framework/allure-behat": "~2.0.0",
...
},
...

## Usage

To enable this extension in [Behat](http://behat.org/en/latest/), add it to `extensions` section of your ```behat.yml``` file:

extensions:
Allure\Behat\AllureFormatterExtension: ~

To use Allure formatter, add `allure` to your list of formatters in `name`:
To enable this extension in [Behat](http://behat.org/en/latest/), add it to `extensions` section of your ```behat.yml``` file
To use Allure formatter, add `allure` to your list of formatters in `name`

```yml

formatter:
name: pretty,allure
parameters:
output: build/allure-report
delete_previous_results: false
ignored_tags: javascript
severity_tag_prefix: 'severity_'
issue_tag_prefix: 'bug_'
test_id_tag_prefix: 'test_case_'

formatters:
pretty: true
allure:
output_path: %paths.base%/build/allure
extensions:
Allure\Behat\AllureFormatterExtension:
severity_key: "severity:"
ignored_tags: "tag_ignore"
issue_tag_prefix: "JIRA:"
test_id_tag_prefix: "BUG:"
```
Here:
- `output` - defines the output dir for report XML data
- `delete_previous_results` - defines whether to remove all files in `output` folder before test run
- `output_path` - defines the output dir for report XML data. Default is `./allure-results`
- `ignored_tags` - either a comma separated string or valid yaml array of Scenario tags to be ignored in reports
- `severity_tag_prefix` - tag with this prefix will be interpreted (if possible) to define the Scenario severity level
- `severity_key` - tag with this prefix will be interpreted (if possible) to define the Scenario severity level
in reports (by default it's `normal`).
- `issue_tag_prefix` - tag with this prefix will be interpreted as Issue marker and will generate issue tracking system
link for test case (using [**allure.issues.tracker.pattern** setting for allure-cli](https://github.com/allure-framework/allure-core/wiki/Issues))
- `test_id_tag_prefix` - tag with this prefix will be interpreted as Test Case Id marker and will generate TMS link for
test case (using [**allure.tests.management.pattern** setting for allure-cli](https://github.com/allure-framework/allure-core/wiki/Test-Case-ID))


### Use attachment support
To have attachments in allure report - make sure your behat runs tests with [Mink](https://github.com/minkphp/Mink)

Allure can handle exception thrown in your Context if that exception is instance of `ArtifactExceptionInterface`
and get screenshots path from it.


### How does it work?

Behat has the following test structure:
Expand All @@ -69,8 +72,8 @@ On the other hand, Allure also supports grouping Test Cases by Feature, by Story
Behat Allure formatter does the following mapping:

* Behat Test Run -> Allure Test Suite
* Behat Scenario (and every single Example in Scenario Outline, too) -> Allure Test Case
* Behat Sentence -> Allure Test Step
* Gherkin Scenario (and every single Example in Scenario Outline, too) -> Allure Test Case
* Gherkin Step -> Allure Test Step

Behat Scenarios are annotated with it's feature title and description to be grouped into Allure Feature.

Expand All @@ -83,5 +86,6 @@ Behat also has tags and they are also can be used in Allure reports:
[Test Case Id](https://github.com/allure-framework/allure-core/wiki/Test-Case-ID) for your TMS
* In all other cases tag will be parsed as Allure Story annotation

By default, this formatter will use `build/allure-results` folder to put it's XML output to. Each Behat run will empty
that folder. To override this behavior, define `output` and `delete_previous_results` parameters respectively.
### Contribution?
Feel free to open PR with changes but before pls make sure you pass tests
`./vendor/behat/behat/bin/behat`
49 changes: 30 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
{
"name": "allure-framework/allure-behat",
"description": "Behat output formatter for use with Yandex Allure reporting tool",
"keywords": ["BDD", "Behat", "Allure"],
"license": "Apache 2.0",
"authors": [
{
"name": "Eduard Sukharev",
"email": "[email protected]"
}
],

"require": {
"php": ">=5.5",
"behat/behat": "~2.4",
"allure-framework/allure-php-api": "~1.1.4"
"name": "allure-framework/allure-behat",
"description": "Behat output formatter for use with Yandex Allure reporting tool",
"keywords": [
"BDD",
"Behat",
"Allure"
],
"license": "Apache 2.0",
"authors": [
{
"name": "Eduard Sukharev",
"email": "[email protected]"
},
"autoload": {
"psr-0": {
"": "src/"
}
{
"name": "Tiko Lakin",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.5",
"behat/behat": "^3.3",
"allure-framework/allure-php-api": "~1.1.4"
},
"require-dev": {
"symfony/process": "~2.5|~3.0|~4.0",
"phpunit/phpunit": "^4.8.36|^6.3"
},
"autoload": {
"psr-0": {
"": "src/"
}
}
}
98 changes: 98 additions & 0 deletions features/allure_formatter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Feature: Allure Formatter
In order integrate with Allure test report tool
As a developer
I need to be able to generate a allure-compatible report

Scenario: Scenario annotation
Given a file named "behat.yml" with:
"""
default:
formatters:
pretty: false
allure: true
extensions:
Allure\Behat\AllureFormatterExtension:
severity_key: "severity:"
ignored_tags: "tag_ignore"
issue_tag_prefix: "JIRA:"
test_id_tag_prefix: "BUG:"
"""
Given a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
class FeatureContext implements Context
{
/**
* @Given /^scenario has annotation$/
*/
public function scenarioHasAnnotation() {
return;
}
/**
* @When /^it passed$/
*/
public function iAdd() {
return;
}
/**
* @Then /^annotation is collected$/
*/
public function somethingNotDoneYet() {
return;
}
}
"""
And a file named "features/World.feature" with:
"""
@tag_feature @severity:blocker @JIRA:PROD-4444
Feature: Annotation
In order to have meta information of the scenario
As a features developer
I want, allure to collect all feature & scenarios tags
@tag_scenario @BUG:7654 @tag_ignore
Scenario: Scenario annotation
Given scenario has annotation
When it passed
Then annotation is collected
"""
When I run "behat --no-colors -f allure -o allure-results"
Then "allure-results/*testsuite.xml" file xml should be like:
"""
<?xml version="1.0" encoding="UTF-8"?>
<alr:test-suite xmlns:alr="urn:model.allure.qatools.yandex.ru" start="-IGNORE-VALUE-" stop="-IGNORE-VALUE-" version="1.4.0">
<name>default</name>
<test-cases>
<test-case start="-IGNORE-VALUE-" stop="-IGNORE-VALUE-" status="passed">
<name>features/World.feature:8</name>
<title>Scenario annotation</title>
<description type="text"><![CDATA[In order to have meta information of the scenario
As a features developer
I want, allure to collect all feature & scenarios tags]]></description>
<steps>
<step start="-IGNORE-VALUE-" stop="-IGNORE-VALUE-" status="passed">
<name>scenario has annotation</name>
<title>Given scenario has annotation</title>
</step>
<step start="-IGNORE-VALUE-" stop="-IGNORE-VALUE-" status="passed">
<name>it passed</name>
<title>When it passed</title>
</step>
<step start="-IGNORE-VALUE-" stop="-IGNORE-VALUE-" status="passed">
<name>annotation is collected</name>
<title>Then annotation is collected</title>
</step>
</steps>
<labels>
<label name="severity" value="blocker"/>
<label name="story" value="tag_feature"/>
<label name="story" value="tag_scenario"/>
<label name="issue" value="PROD-4444"/>
<label name="testId" value="7654"/>
</labels>
</test-case>
</test-cases>
</alr:test-suite>
"""
Loading

0 comments on commit ae42eb3

Please sign in to comment.