Skip to content

Commit 8aee6af

Browse files
committed
MQE-659: [ALLURE] Include the test "stepKey" in the MFTF Allure Report
- test fixes
1 parent eb87ccf commit 8aee6af

File tree

6 files changed

+102
-44
lines changed

6 files changed

+102
-44
lines changed

dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ class ActionGroupWithStepKeyReferencesCest
4444
$I->fillField($action1); // stepKey: action1ActionGroup
4545
$I->comment("Invocation stepKey will be appended in non stepKey instances");
4646
$action3ActionGroup = $I->executeJS($action3ActionGroup); // stepKey: action3ActionGroup
47-
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, "\"stuffHere\""); $I->comment($action4ActionGroup);
48-
// stepKey: action4ActionGroup
47+
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, "\"stuffHere\""); // stepKey: action4ActionGroup
48+
$I->comment($action4ActionGroup);
49+
4950
$date = new \DateTime();
5051
$date->setTimestamp(strtotime("{$action5}"));
5152
$date->setTimezone(new \DateTimeZone("America/Los_Angeles"));
5253
$action5ActionGroup = $date->format("H:i:s");
53-
// stepKey: action5ActionGroup
54+
5455
$action6ActionGroup = $I->formatMoney($action6ActionGroup); // stepKey: action6ActionGroup
5556
$I->comment("[action7ActionGroup] delete entity '{$action7ActionGroupActionGroup}'");
5657
PersistedObjectHandler::getInstance()->deleteEntity(

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,21 @@ class BasicFunctionalTestCest
107107
$date->setTimestamp(strtotime("Now"));
108108
$date->setTimezone(new \DateTimeZone("America/Los_Angeles"));
109109
$generateDateKey = $date->format("H:i:s");
110-
// stepKey: generateDateKey
110+
111111
$date = new \DateTime();
112112
$date->setTimestamp(strtotime("Now"));
113113
$date->setTimezone(new \DateTimeZone("UTC"));
114114
$generateDateKey2 = $date->format("H:i:s");
115-
// stepKey: generateDateKey2
115+
116116
$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput"); // stepKey: grabAttributeFromKey1
117117
$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']); // stepKey: grabCookieKey1
118118
$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl"); // stepKey: grabFromCurrentUrlKey1
119119
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector"); // stepKey: grabMultipleKey1
120120
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector"); // stepKey: grabTextFromKey1
121121
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector"); // stepKey: grabValueFromKey1
122-
$magentoCli1 = $I->magentoCLI("maintenance:enable", "\"stuffHere\""); $I->comment($magentoCli1);
123-
// stepKey: magentoCli1
122+
$magentoCli1 = $I->magentoCLI("maintenance:enable", "\"stuffHere\""); // stepKey: magentoCli1
123+
$I->comment($magentoCli1);
124+
124125
$I->makeScreenshot("screenShotInput"); // stepKey: makeScreenshotKey1
125126
$I->maximizeWindow(); // stepKey: maximizeWindowKey1
126127
$I->moveBack(); // stepKey: moveBackKey1

dev/tests/verification/Resources/DataReplacementTest.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class DataReplacementTestCest
5151
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]); // stepKey: parameterArrayReplacementMSQBoth
5252
$I->selectMultipleOptions("#Doe" . msq("uniqueData"), "#element", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]); // stepKey: multiSelectDataReplacement
5353
$I->fillField(".selector", "0"); // stepKey: insertZero
54-
$insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness"); $I->comment($insertCommand);
55-
// stepKey: insertCommand
54+
$insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness"); // stepKey: insertCommand
55+
$I->comment($insertCommand);
56+
5657
}
5758
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,31 @@ public function testEnd()
196196
$formattedSteps = [];
197197
$actionGroupStepContainer = null;
198198

199+
$actionGroupStepKey = null;
199200
foreach ($rootStep->getSteps() as $step) {
201+
if ($actionGroupStepKey !== null) {
202+
$stepKey = str_replace($actionGroupStepKey, '', $step->getName());
203+
if ($stepKey !== '[]' && $stepKey !== null) {
204+
$step->setName($stepKey);
205+
}
206+
}
200207
// if actionGroup flag, start nesting
201208
if (strpos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false) {
202209
$step->setName(str_replace(ActionGroupObject::ACTION_GROUP_CONTEXT_START, '', $step->getName()));
203210
$actionGroupStepContainer = $step;
211+
212+
preg_match('/\[(?<actionGroupStepKey>.*)\]/', $step->getName(), $matches);
213+
if (!empty($matches['actionGroupStepKey'])) {
214+
$actionGroupStepKey = ucfirst($matches['actionGroupStepKey']);
215+
}
204216
continue;
205217
}
218+
206219
// if actionGroup ended, add stack to steps
207220
if (stripos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_END) !== false) {
208221
$formattedSteps[] = $actionGroupStepContainer;
209222
$actionGroupStepContainer = null;
223+
$actionGroupStepKey = null;
210224
continue;
211225
}
212226

@@ -253,12 +267,11 @@ private function retrieveStepKey($stepLine)
253267
if (!array_key_exists($filePath, $this->testFiles)) {
254268
$this->testFiles[$filePath] = explode(PHP_EOL, file_get_contents($filePath));
255269
}
256-
$testLineTrimmed = substr(
257-
$this->testFiles[$filePath][$stepLine],
258-
strpos($this->testFiles[$filePath][$stepLine], '//')
259-
);
260270

261-
list($stepKey) = sscanf($testLineTrimmed, TestGenerator::STEP_KEY_ANNOTATION);
271+
preg_match("/\/\/ stepKey: (?<stepKey>.*)/", $this->testFiles[$filePath][$stepLine], $matches);
272+
if (!empty($matches['stepKey'])) {
273+
$stepKey = $matches['stepKey'];
274+
}
262275

263276
return $stepKey;
264277
}

src/Magento/FunctionalTestingFramework/Codeception/Subscriber/Console.php

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
72
namespace Magento\FunctionalTestingFramework\Codeception\Subscriber;
83

9-
use Codeception\Event\FailEvent;
10-
use Codeception\Event\PrintResultEvent;
114
use Codeception\Event\StepEvent;
12-
use Codeception\Event\SuiteEvent;
13-
use Codeception\Event\TestEvent;
14-
use Codeception\Events;
155
use Codeception\Lib\Console\Message;
16-
use Codeception\Lib\Console\MessageFactory;
17-
use Codeception\Lib\Console\Output;
18-
use Codeception\Lib\Notification;
196
use Codeception\Step;
207
use Codeception\Step\Comment;
21-
use Codeception\Suite;
22-
use Codeception\Test\Descriptor;
238
use Codeception\Test\Interfaces\ScenarioDriven;
24-
use Codeception\Util\Debug;
25-
use Magento\FunctionalTestingFramework\Util\TestGenerator;
26-
use Symfony\Component\Console\Output\OutputInterface;
9+
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
2710
use Symfony\Component\Console\Formatter\OutputFormatter;
28-
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2911

3012
class Console extends \Codeception\Subscriber\Console
3113
{
@@ -36,6 +18,13 @@ class Console extends \Codeception\Subscriber\Console
3618
*/
3719
private $testFiles = [];
3820

21+
/**
22+
* Action group step key.
23+
*
24+
* @var null|string
25+
*/
26+
private $actionGroupStepKey = null;
27+
3928
/**
4029
* Printing stepKey in before step action.
4130
*
@@ -44,9 +33,10 @@ class Console extends \Codeception\Subscriber\Console
4433
*/
4534
public function beforeStep(StepEvent $e)
4635
{
47-
if (!$this->steps or !$e->getTest() instanceof ScenarioDriven) {
36+
if ($this->silent or !$this->steps or !$e->getTest() instanceof ScenarioDriven) {
4837
return;
4938
}
39+
5040
$metaStep = $e->getStep()->getMetaStep();
5141
if ($metaStep and $this->metaStep != $metaStep) {
5242
$this->message(' ' . $metaStep->getPrefix())
@@ -59,6 +49,20 @@ public function beforeStep(StepEvent $e)
5949
$this->printStepKeys($e->getStep());
6050
}
6151

52+
/**
53+
* If step failed we move back from action group to test scope
54+
*
55+
* @param StepEvent $e
56+
* @return void
57+
*/
58+
public function afterStep(StepEvent $e)
59+
{
60+
parent::afterStep($e);
61+
if ($e->getStep()->hasFailed()) {
62+
$this->actionGroupStepKey = null;
63+
}
64+
}
65+
6266
/**
6367
* Print output to cli with stepKey.
6468
*
@@ -73,20 +77,44 @@ private function printStepKeys(Step $step)
7377

7478
$stepKey = $this->retrieveStepKey($step->getLine());
7579

76-
$msg = $this->message(' ');
77-
if ($this->metaStep) {
80+
$isActionGroup = (strpos($step->__toString(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false);
81+
if ($isActionGroup) {
82+
preg_match('/\[(?<actionGroupStepKey>.*)\]/', $step->__toString(), $matches);
83+
if (!empty($matches['actionGroupStepKey'])) {
84+
$this->actionGroupStepKey = ucfirst($matches['actionGroupStepKey']);
85+
}
86+
}
87+
88+
if (strpos($step->__toString(), ActionGroupObject::ACTION_GROUP_CONTEXT_END) !== false) {
89+
$this->actionGroupStepKey = null;
90+
return;
91+
}
92+
93+
$msg = $this->message();
94+
if ($this->metaStep || ($this->actionGroupStepKey !== null && !$isActionGroup)) {
7895
$msg->append(' ');
7996
}
8097
if ($stepKey !== null) {
8198
$msg->append(OutputFormatter::escape("[" . $stepKey . "] "));
99+
$msg->style('bold');
82100
}
83101

84102
if (!$this->metaStep) {
85103
$msg->style('bold');
86104
}
87105

88-
$msg->append(OutputFormatter::escape($step->toString($this->width)));
89-
if ($this->metaStep) {
106+
$stepString = str_replace(
107+
[ActionGroupObject::ACTION_GROUP_CONTEXT_START, ActionGroupObject::ACTION_GROUP_CONTEXT_END],
108+
'',
109+
$step->toString(150)
110+
);
111+
112+
113+
$msg->append(OutputFormatter::escape($stepString));
114+
if ($isActionGroup) {
115+
$msg->style('comment');
116+
}
117+
if ($this->metaStep || ($this->actionGroupStepKey !== null && !$isActionGroup)) {
90118
$msg->style('info');
91119
}
92120
$msg->writeln();
@@ -118,12 +146,17 @@ private function retrieveStepKey($stepLine)
118146
if (!array_key_exists($filePath, $this->testFiles)) {
119147
$this->testFiles[$filePath] = explode(PHP_EOL, file_get_contents($filePath));
120148
}
121-
$testLineTrimmed = substr(
122-
$this->testFiles[$filePath][$stepLine],
123-
strpos($this->testFiles[$filePath][$stepLine], '//')
124-
);
125149

126-
list($stepKey) = sscanf($testLineTrimmed, TestGenerator::STEP_KEY_ANNOTATION);
150+
preg_match("/\/\/ stepKey: (?<stepKey>.*)/", $this->testFiles[$filePath][$stepLine], $matches);
151+
if (!empty($matches['stepKey'])) {
152+
$stepKey = $matches['stepKey'];
153+
}
154+
155+
if ($this->actionGroupStepKey !== null) {
156+
$stepKey = str_replace($this->actionGroupStepKey, '', $stepKey);
157+
}
158+
159+
$stepKey = $stepKey === '[]' ? null : $stepKey;
127160

128161
return $stepKey;
129162
}

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ class TestGenerator
3939
const SUITE_SCOPE = 'suite';
4040
const PRESSKEY_ARRAY_ANCHOR_KEY = '987654321098765432109876543210';
4141
const PERSISTED_OBJECT_NOTATION_REGEX = '/\${1,2}[\w.\[\]]+\${1,2}/';
42-
const NO_STEPKEY_ACTIONS = ['comment', 'createData', 'deleteData', 'updateData', 'getData'];
42+
const NO_STEPKEY_ACTIONS = [
43+
'comment',
44+
'createData',
45+
'deleteData',
46+
'updateData',
47+
'getData',
48+
'magentoCLI',
49+
'generateDate'
50+
];
4351
const STEP_KEY_ANNOTATION = " // stepKey: %s";
4452

4553
/**
@@ -1262,6 +1270,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12621270
$command,
12631271
$arguments
12641272
);
1273+
$testSteps .= sprintf(self::STEP_KEY_ANNOTATION, $stepKey) . PHP_EOL;
12651274
$testSteps .= sprintf(
12661275
"\t\t$%s->comment(\$%s);\n",
12671276
$actor,

0 commit comments

Comments
 (0)