Skip to content

Commit ca8a901

Browse files
committed
MQE-1672: AllureAdapter does not output BROKEN test steps
- Fixed broken steps not showing up at all - Fixed ActionGroup nesting issues when the test abruptly ends
1 parent ba310f5 commit ca8a901

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1010
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
1111
use \Magento\FunctionalTestingFramework\Util\TestGenerator;
12+
use Yandex\Allure\Adapter\Model\Status;
1213
use Yandex\Allure\Adapter\Model\Step;
1314
use Yandex\Allure\Codeception\AllureCodeception;
1415
use Yandex\Allure\Adapter\Event\StepStartedEvent;
1516
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
1617
use Yandex\Allure\Adapter\Event\StepFailedEvent;
1718
use Yandex\Allure\Adapter\Event\TestCaseFailedEvent;
1819
use Yandex\Allure\Adapter\Event\TestCaseFinishedEvent;
20+
use Yandex\Allure\Adapter\Event\TestCaseBrokenEvent;
1921
use Codeception\Event\FailEvent;
2022
use Codeception\Event\SuiteEvent;
2123
use Codeception\Event\StepEvent;
@@ -187,6 +189,32 @@ public function testIncomplete(FailEvent $failEvent)
187189
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
188190
}
189191

192+
/**
193+
* Override of parent method. Adds in steps for hard PHP Errors if they arrise.
194+
*
195+
* @param FailEvent $failEvent
196+
* @return void
197+
*/
198+
public function testError(FailEvent $failEvent)
199+
{
200+
$event = new TestCaseBrokenEvent();
201+
$e = $failEvent->getFail();
202+
$message = $e->getMessage();
203+
204+
// Create new step with an error for Allure
205+
$failStep = new Step();
206+
$failStep->setName("ERROR");
207+
$failStep->setTitle($message);
208+
$failStep->setStatus(Status::BROKEN);
209+
210+
// Retrieve Allure Steps and add in the new BROKEN step
211+
$rootStep = $this->getLifecycle()->getStepStorage()->pollLast();
212+
$rootStep->addStep($failStep);
213+
$this->getLifecycle()->getStepStorage()->put($rootStep);
214+
215+
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
216+
}
217+
190218
/**
191219
* Override of parent method, polls stepStorage for testcase and formats it according to actionGroup nesting.
192220
*
@@ -207,6 +235,13 @@ public function testEnd()
207235
}
208236
// if actionGroup flag, start nesting
209237
if (strpos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false) {
238+
if ($actionGroupStepContainer !== null) {
239+
//actionGroup still being nested, need to close out and finish it.
240+
$formattedSteps[] = $actionGroupStepContainer;
241+
$actionGroupStepContainer = null;
242+
$actionGroupStepKey = null;
243+
}
244+
210245
$step->setName(str_replace(ActionGroupObject::ACTION_GROUP_CONTEXT_START, '', $step->getName()));
211246
$actionGroupStepContainer = $step;
212247

0 commit comments

Comments
 (0)