Skip to content

Commit 79c2af9

Browse files
committed
MQE-1472: Action Group context in Tests and Allure
- Added Context comment in ActionGroupObject - Allure now nests actionGroup steps a parent step
1 parent db370cf commit 79c2af9

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

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

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
namespace Magento\FunctionalTestingFramework\Allure\Adapter;
77

88
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
9+
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
10+
use Yandex\Allure\Adapter\Model\Step;
911
use Yandex\Allure\Codeception\AllureCodeception;
1012
use Yandex\Allure\Adapter\Event\StepStartedEvent;
1113
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
1214
use Yandex\Allure\Adapter\Event\StepFailedEvent;
1315
use Yandex\Allure\Adapter\Event\TestCaseFailedEvent;
16+
use Yandex\Allure\Adapter\Event\TestCaseFinishedEvent;
1417
use Codeception\Event\FailEvent;
1518
use Codeception\Event\SuiteEvent;
1619
use Codeception\Event\StepEvent;
@@ -25,6 +28,8 @@
2528

2629
class MagentoAllureAdapter extends AllureCodeception
2730
{
31+
const STEP_PASSED = "passed";
32+
2833
/**
2934
* Array of group values passed to test runner command
3035
*
@@ -107,7 +112,13 @@ public function stepBefore(StepEvent $stepEvent)
107112
{
108113
//Hard set to 200; we don't expose this config in MFTF
109114
$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+
}
111122
$stepArgs = $stepEvent->getStep()->getArgumentsAsString($argumentsLength);
112123

113124
if (!trim($stepAction)) {
@@ -148,4 +159,54 @@ public function testIncomplete(FailEvent $failEvent)
148159
$message = $e->getMessage();
149160
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
150161
}
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+
}
151212
}

src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class ActionGroupObject
1919
{
2020
const ACTION_GROUP_ORIGIN_NAME = "actionGroupName";
2121
const ACTION_GROUP_ORIGIN_TEST_REF = "testInvocationRef";
22+
const ACTION_GROUP_CONTEXT_START = "Entering Action Group ";
23+
const ACTION_GROUP_CONTEXT_END = "Exiting Action Group";
2224
const STEPKEY_REPLACEMENT_ENABLED_TYPES = [
2325
"executeJS",
2426
"magentoCLI",
@@ -190,6 +192,8 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
190192
);
191193
}
192194

195+
$resolvedActions = $this->addContextCommentsToActionList($resolvedActions);
196+
193197
return $resolvedActions;
194198
}
195199

@@ -481,4 +485,24 @@ private function replaceCreateDataKeys($action, $replacementStepKeys)
481485

482486
return $resolvedActionAttributes;
483487
}
488+
489+
/**
490+
* Adds comment ActionObjects before and after given actionList for context setting.
491+
* @param array $actionList
492+
* @return array
493+
*/
494+
private function addContextCommentsToActionList($actionList)
495+
{
496+
$startAction = new ActionObject(
497+
self::ACTION_GROUP_CONTEXT_START . $this->name,
498+
ActionObject::ACTION_TYPE_COMMENT,
499+
[ActionObject::ACTION_ATTRIBUTE_USERINPUT => self::ACTION_GROUP_CONTEXT_START . $this->name]
500+
);
501+
$endAction = new ActionObject(
502+
self::ACTION_GROUP_CONTEXT_END,
503+
ActionObject::ACTION_TYPE_COMMENT,
504+
[ActionObject::ACTION_ATTRIBUTE_USERINPUT => self::ACTION_GROUP_CONTEXT_END]
505+
);
506+
return [$startAction->getStepKey() => $startAction] + $actionList + [$endAction->getStepKey() => $endAction];
507+
}
484508
}

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class ActionObject
6969
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
7070
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\((?(?!}}).)+\)}})/';
7171
const DEFAULT_WAIT_TIMEOUT = 10;
72+
const ACTION_ATTRIBUTE_USERINPUT = 'userInput';
73+
const ACTION_TYPE_COMMENT = 'comment';
7274

7375
/**
7476
* The unique identifier for the action

0 commit comments

Comments
 (0)