From f697f8b91ed35821c453f84c63de4a5282d29fbd Mon Sep 17 00:00:00 2001 From: ebo Date: Fri, 24 May 2019 11:36:04 +0100 Subject: [PATCH 1/3] Added support for Allure epic and feature tags --- README.md | 36 ++++++++ src/Allure/Behat/AllureFormatterExtension.php | 6 ++ .../Behat/Formatter/AllureFormatter.php | 82 ++++++++++++++++++- 3 files changed, 120 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 589f7eb..2fe0660 100644 --- a/README.md +++ b/README.md @@ -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) @@ -86,6 +90,38 @@ 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 +- `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 +- `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` diff --git a/src/Allure/Behat/AllureFormatterExtension.php b/src/Allure/Behat/AllureFormatterExtension.php index aa17641..41e0abe 100644 --- a/src/Allure/Behat/AllureFormatterExtension.php +++ b/src/Allure/Behat/AllureFormatterExtension.php @@ -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); } /** @@ -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); diff --git a/src/Allure/Behat/Formatter/AllureFormatter.php b/src/Allure/Behat/Formatter/AllureFormatter.php index c66ad9b..c478e8f 100644 --- a/src/Allure/Behat/Formatter/AllureFormatter.php +++ b/src/Allure/Behat/Formatter/AllureFormatter.php @@ -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; @@ -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; @@ -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(); @@ -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(); 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(); @@ -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) @@ -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()) { From e3695c21ff92ba8c8cefff0bc88cb46a13bd96d3 Mon Sep 17 00:00:00 2001 From: ebo Date: Fri, 24 May 2019 11:40:46 +0100 Subject: [PATCH 2/3] Updated documentation about alternative configuration --- README.md | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2fe0660..a4e31ff 100644 --- a/README.md +++ b/README.md @@ -95,32 +95,44 @@ Behat also has tags and they are also can be used in Allure reports: 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 -- `feature_tag_prefix= "Capability:"` -- `story_tag_prefix= "."` +```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 +``` +Customers + Creating new customers +``` #### Example using BDD business domains, capabilities and features -- `epic_tag_prefix= "BusinessDomain:"` -- `feature_tag_prefix= "Capability:"` -- `story_tag_prefix= "."` +```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 +``` +CRM + Customers + Creating new customers +``` ### Contribution? Feel free to open PR with changes but before pls make sure you pass tests From 1049e6340f2fd4e5431a9023f95d7322e5e45b2c Mon Sep 17 00:00:00 2001 From: ebo Date: Fri, 24 May 2019 17:31:24 +0100 Subject: [PATCH 3/3] Update dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b45c2c6..29a0cdc 100644 --- a/composer.json +++ b/composer.json @@ -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" }, "autoload": { "psr-0": {