Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Allure 'epic' and 'feature' tags #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Here:
- `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))

Optionally, you can add the following options:
- `epic_tag_prefix` - tags with this prefix will be added as Allure Epic tags
- `feature_tag_prefix` - tags with this prefix will be added as Allure Feature tags
- `story_tag_prefix` - tags with this prefix will be added as Allure Story tags, if you set `story_tag_prefix: "."` the story tag will be filled with the name of the feature name

### Use attachment support
To have attachments in allure report - make sure your behat runs tests with [Mink](https://github.com/minkphp/Mink)
Expand Down Expand Up @@ -86,6 +90,50 @@ 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

### Alternative configuration

You can change this standard behaviour by setting the `epic_tag_prefix`, `feature_tag_prefix` and `story_tag_prefix`.

#### Example using BDD capabilities and features
```yml
feature_tag_prefix: "Capability:"
story_tag_prefix: "."
```

A `test.feature` file with the following content:

```
@Capability:Customers
Feature: Creating new customers
```

Will report the results as:
```
Customers
Creating new customers
```

#### Example using BDD business domains, capabilities and features
```yml
epic_tag_prefix: "BusinessDomain:"
feature_tag_prefix: "Capability:"
story_tag_prefix: "."
```

A `test.feature` file with the following content:

```
@BusinessDomain:CRM @Capability:Customers
Feature: Creating new customers
```

Will report the results as:
```
CRM
Customers
Creating new customers
```

### Contribution?
Feel free to open PR with changes but before pls make sure you pass tests
`./vendor/behat/behat/bin/behat`
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
],
"require": {
"php": ">=5.5",
"behat/behat": "^3.3",
"allure-framework/allure-php-api": "~1.1.4"
"behat/behat": "^3.3"
},
"require-dev": {
"symfony/process": "~2.5|~3.0|~4.0",
"phpunit/phpunit": "^4.8.36|^6.3"
"phpunit/phpunit": "^4.8.36|^6.3",
"allure-framework/allure-php-api": "~1.1.5"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this actually be moved into require-dev? Can you "run" it without allure-php-api, just with behat and php?

},
"autoload": {
"psr-0": {
Expand Down
6 changes: 6 additions & 0 deletions src/Allure/Behat/AllureFormatterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function configure(ArrayNodeDefinition $builder)
$builder->children()->scalarNode("test_id_tag_prefix")->defaultValue(null);
$builder->children()->scalarNode("ignored_tags")->defaultValue(null);
$builder->children()->scalarNode("severity_key")->defaultValue(null);
$builder->children()->scalarNode("epic_tag_prefix")->defaultValue(null);
$builder->children()->scalarNode("feature_tag_prefix")->defaultValue(null);
$builder->children()->scalarNode("story_tag_prefix")->defaultValue(null);
}

/**
Expand All @@ -95,6 +98,9 @@ public function load(ContainerBuilder $container, array $config)
$definition->addArgument($config['test_id_tag_prefix']);
$definition->addArgument($config['ignored_tags']);
$definition->addArgument($config['severity_key']);
$definition->addArgument($config['epic_tag_prefix']);
$definition->addArgument($config['feature_tag_prefix']);
$definition->addArgument($config['story_tag_prefix']);
$definition->addArgument('%paths.base%');
$presenter = new Reference(ExceptionExtension::PRESENTER_ID);
$definition->addArgument($presenter);
Expand Down
82 changes: 78 additions & 4 deletions src/Allure/Behat/Formatter/AllureFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Epics;
use Yandex\Allure\Adapter\Annotation\TestCaseId;
use Yandex\Allure\Adapter\Event\StepCanceledEvent;
use Yandex\Allure\Adapter\Event\StepFailedEvent;
Expand Down Expand Up @@ -85,6 +87,9 @@ class AllureFormatter implements Formatter
protected $testIdTagPrefix;
protected $ignoredTags;
protected $severity_key;
protected $epicTagPrefix;
protected $featureTagPrefix;
protected $storyTagPrefix;
protected $parameters;
protected $printer;
protected $outlineCounter = 0;
Expand All @@ -99,13 +104,16 @@ class AllureFormatter implements Formatter

use AttachmentSupport;

public function __construct($name, $issue_tag_prefix, $test_id_tag_prefix, $ignoredTags, $severity_key, $base_path, $presenter)
public function __construct($name, $issue_tag_prefix, $test_id_tag_prefix, $ignoredTags, $severity_key, $epic_tag_prefix, $feature_tag_prefix, $story_tag_prefix, $base_path, $presenter)
{
$this->name = $name;
$this->issueTagPrefix = $issue_tag_prefix;
$this->testIdTagPrefix = $test_id_tag_prefix;
$this->ignoredTags = $ignoredTags;
$this->severity_key = $severity_key;
$this->epicTagPrefix = $epic_tag_prefix;
$this->featureTagPrefix = $feature_tag_prefix;
$this->storyTagPrefix = $story_tag_prefix;
$this->base_path = $base_path;
$this->presenter = $presenter;
$this->timer = new Timer();
Expand Down Expand Up @@ -327,7 +335,7 @@ public function onAfterStepTested(AfterStepTested $event)
$result = $event->getTestResult();

if ($result instanceof ExceptionResult && $result->hasException()) {
$this->exception = $result->getException();
$this->exception = $result->getException();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why extra spacing?

if ($this->exception instanceof ArtifactExceptionInterface) {
$this->attachment[md5_file($this->exception->getScreenPath())] = $this->exception->getScreenPath();
$this->attachment[md5_file($this->exception->getHtmlPath())] = $this->exception->getHtmlPath();
Expand Down Expand Up @@ -369,7 +377,53 @@ protected function parseFeatureAnnotations(FeatureNode $featureNode)
$description = new Description();
$description->type = DescriptionType::TEXT;
$description->value = $featureNode->getDescription();
return [$this->scopeAnnotation, $description];

$annotations = [$this->scopeAnnotation, $description];

if (class_exists('\Yandex\Allure\Adapter\Annotation\Epics')) {
$epic = new Epics();
$epic->epicNames = [];
}
$feature = new Features();
$feature->featureNames = [];
$story = new Stories();
$story->stories = [];

foreach ($this->scopeAnnotation as $tag) {
if (isset($epic) && $this->epicTagPrefix) {
if (stripos(strtolower($tag), strtolower($this->epicTagPrefix)) === 0) {
$epic->epicNames[] = substr($tag, strlen($this->epicTagPrefix));
}
}
if ($this->featureTagPrefix) {
if (stripos(strtolower($tag), strtolower($this->featureTagPrefix)) === 0) {
$feature->featureNames[] = substr($tag, strlen($this->featureTagPrefix));
}
}
if ($this->storyTagPrefix && $this->storyTagPrefix != '.') {
if (stripos(strtolower($tag), strtolower($this->storyTagPrefix)) === 0) {
$story->stories[] = substr($tag, strlen($this->storyTagPrefix));
}
}
}

if ($this->storyTagPrefix == '.') {
$story->stories[] = $featureNode->getTitle();
}

if (isset($epic) && $epic->getEpicNames()) {
array_push($annotations, $epic);
}

if ($feature->getFeatureNames()) {
array_push($annotations, $feature);
}

if ($story->getStories()) {
array_push($annotations, $story);
}

return $annotations;
}

protected function parseScenarioAnnotations(ScenarioInterface $scenarioNode)
Expand Down Expand Up @@ -432,7 +486,27 @@ protected function parseScenarioAnnotations(ScenarioInterface $scenarioNode)
continue;
}

$story->stories[] = $tag;
if ($this->epicTagPrefix) {
if (stripos(strtolower($tag), strtolower($this->epicTagPrefix)) === 0) {
continue;
}
}

if ($this->featureTagPrefix) {
if (stripos(strtolower($tag), strtolower($this->featureTagPrefix)) === 0) {
continue;
}
}

if ($this->storyTagPrefix) {
if ($this->storyTagPrefix == '.'){
continue;
} elseif (stripos(strtolower($tag), strtolower($this->storyTagPrefix)) === 0) {
continue;
}
} else {
$story->stories[] = $tag;
}
}

if ($story->getStories()) {
Expand Down