|
6 | 6 | namespace Magento\FunctionalTestingFramework\Allure\Adapter;
|
7 | 7 |
|
8 | 8 | use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
|
| 9 | +use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject; |
| 10 | +use Yandex\Allure\Adapter\Model\Step; |
9 | 11 | use Yandex\Allure\Codeception\AllureCodeception;
|
10 | 12 | use Yandex\Allure\Adapter\Event\StepStartedEvent;
|
11 | 13 | use Yandex\Allure\Adapter\Event\StepFinishedEvent;
|
12 | 14 | use Yandex\Allure\Adapter\Event\StepFailedEvent;
|
13 | 15 | use Yandex\Allure\Adapter\Event\TestCaseFailedEvent;
|
| 16 | +use Yandex\Allure\Adapter\Event\TestCaseFinishedEvent; |
14 | 17 | use Codeception\Event\FailEvent;
|
15 | 18 | use Codeception\Event\SuiteEvent;
|
16 | 19 | use Codeception\Event\StepEvent;
|
|
25 | 28 |
|
26 | 29 | class MagentoAllureAdapter extends AllureCodeception
|
27 | 30 | {
|
| 31 | + const STEP_PASSED = "passed"; |
| 32 | + |
28 | 33 | /**
|
29 | 34 | * Array of group values passed to test runner command
|
30 | 35 | *
|
@@ -107,7 +112,13 @@ public function stepBefore(StepEvent $stepEvent)
|
107 | 112 | {
|
108 | 113 | //Hard set to 200; we don't expose this config in MFTF
|
109 | 114 | $argumentsLength = 200;
|
110 |
| - $stepAction = $stepEvent->getStep()->getHumanizedActionWithoutArguments(); |
| 115 | + |
| 116 | + // DO NOT alter action if actionGroup is starting, need the exact actionGroup name for good logging |
| 117 | + if (strpos($stepEvent->getStep()->getAction(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false) { |
| 118 | + $stepAction = $stepEvent->getStep()->getAction(); |
| 119 | + } else { |
| 120 | + $stepAction = $stepEvent->getStep()->getHumanizedActionWithoutArguments(); |
| 121 | + } |
111 | 122 | $stepArgs = $stepEvent->getStep()->getArgumentsAsString($argumentsLength);
|
112 | 123 |
|
113 | 124 | if (!trim($stepAction)) {
|
@@ -148,4 +159,54 @@ public function testIncomplete(FailEvent $failEvent)
|
148 | 159 | $message = $e->getMessage();
|
149 | 160 | $this->getLifecycle()->fire($event->withException($e)->withMessage($message));
|
150 | 161 | }
|
| 162 | + |
| 163 | + /** |
| 164 | + * Override of parent method, polls stepStorage for testcase and formats it according to actionGroup nesting. |
| 165 | + * |
| 166 | + * @return void |
| 167 | + */ |
| 168 | + public function testEnd() |
| 169 | + { |
| 170 | + $rootStep = $this->getLifecycle()->getStepStorage()->pollLast(); |
| 171 | + $formattedStep = new Step(); |
| 172 | + $formattedStep->setName($rootStep->getName()); |
| 173 | + $formattedStep->setStart($rootStep->getStart()); |
| 174 | + $formattedStep->setStatus($rootStep->getStatus()); |
| 175 | + |
| 176 | + $actionGroupStepContainer = null; |
| 177 | + |
| 178 | + foreach ($rootStep->getSteps() as $step) { |
| 179 | + // if actionGroup flag, start nesting |
| 180 | + if (strpos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false) { |
| 181 | + $step->setName(str_replace(ActionGroupObject::ACTION_GROUP_CONTEXT_START, '', $step->getName())); |
| 182 | + $actionGroupStepContainer = $step; |
| 183 | + continue; |
| 184 | + } |
| 185 | + // if actionGroup ended, add stack to steps |
| 186 | + if (stripos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_END) !== false) { |
| 187 | + $formattedStep->addStep($actionGroupStepContainer); |
| 188 | + $actionGroupStepContainer = null; |
| 189 | + continue; |
| 190 | + } |
| 191 | + |
| 192 | + if ($actionGroupStepContainer !== null) { |
| 193 | + $actionGroupStepContainer->addStep($step); |
| 194 | + if ($step->getStatus() !== self::STEP_PASSED) { |
| 195 | + // If step didn't pass, need to end action group nesting and set overall step status |
| 196 | + $actionGroupStepContainer->setStatus($step->getStatus()); |
| 197 | + $formattedStep->addStep($actionGroupStepContainer); |
| 198 | + $actionGroupStepContainer = null; |
| 199 | + } |
| 200 | + } else { |
| 201 | + // Add step as normal |
| 202 | + $formattedStep->addStep($step); |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + // Reset storage with new formatted nested steps |
| 207 | + $this->getLifecycle()->getStepStorage()->clear(); |
| 208 | + $this->getLifecycle()->getStepStorage()->put($formattedStep); |
| 209 | + |
| 210 | + $this->getLifecycle()->fire(new TestCaseFinishedEvent()); |
| 211 | + } |
151 | 212 | }
|
0 commit comments