From fad2ccc0f265d5ad2849d747c0438d3f07f04071 Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Thu, 23 May 2019 09:35:19 -0500 Subject: [PATCH 1/3] MQE-659: [ALLURE] Include the test "stepKey" in the MFTF Allure Report --- .../Allure/Adapter/MagentoAllureAdapter.php | 80 ++++++ .../Adapter/MagentoAllureStepKeyReader.php | 234 ++++++++++++++++++ .../Util/TestGenerator.php | 114 +++++---- 3 files changed, 377 insertions(+), 51 deletions(-) create mode 100644 src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php diff --git a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php index 65be8ea84..1fb407809 100644 --- a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php +++ b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php @@ -7,6 +7,8 @@ use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler; use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject; +use Magento\FunctionalTestingFramework\Allure\Adapter\MagentoAllureStepKeyReader; +use Magento\FunctionalTestingFramework\Util\TestGenerator; use Yandex\Allure\Adapter\Model\Step; use Yandex\Allure\Codeception\AllureCodeception; use Yandex\Allure\Adapter\Event\StepStartedEvent; @@ -17,6 +19,7 @@ use Codeception\Event\FailEvent; use Codeception\Event\SuiteEvent; use Codeception\Event\StepEvent; +use Codeception\Event\TestEvent; /** * Class MagentoAllureAdapter @@ -30,6 +33,23 @@ class MagentoAllureAdapter extends AllureCodeception { const STEP_PASSED = "passed"; + const SAVE_SCREENSHOT = "save screenshot"; + const ALLURE_STEPKEY_FORMAT = " ------ @stepKey="; + + /** + * @var integer + */ + private $stepCount; + + /** + * @var array + */ + private $stepKeys; + + /** + * @var MagentoAllureStepKeyReader + */ + private $stepKeyReader; /** * Array of group values passed to test runner command @@ -179,7 +199,13 @@ public function testEnd() $formattedSteps = []; $actionGroupStepContainer = null; + // Get properly ordered step keys for this test + $this->stepKeys = $this->stepKeyReader->getSteps($this->getPassedStepCount($rootStep)); + + $stepCount = -1; foreach ($rootStep->getSteps() as $step) { + $stepCount += 1; + $step->setName($this->appendStepKey($stepCount, $step->getName())); // if actionGroup flag, start nesting if (strpos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false) { $step->setName(str_replace(ActionGroupObject::ACTION_GROUP_CONTEXT_START, '', $step->getName())); @@ -220,4 +246,58 @@ function () use ($rootStep, $formattedSteps) { $this->getLifecycle()->fire(new TestCaseFinishedEvent()); } + + /** + * Aggregate to parent method to prepare collecting step keys for a test + * + * @return void + */ + public function testStart(TestEvent $testEvent) + { + $this->stepKeys = []; + $this->stepCount = 0; + $this->stepKeyReader = new MagentoAllureStepKeyReader( + $testEvent->getTest()->getFileName(), + $testEvent->getTest()->getTestMethod() + ); + parent::testStart($testEvent); + } + + /** + * Append step key to matching step + * + * @param integer $stepCount + * @param string $name + * + * @return string + */ + private function appendStepKey($stepCount, $name) + { + if (isset($this->stepKeys[$stepCount]['action']) && isset($this->stepKeys[$stepCount]['stepKey'])) { + if ($this->stepKeys[$stepCount]['action'] == "comment" + || strpos($name, $this->stepKeys[$stepCount]['action']) !== false) { + $name .= self::ALLURE_STEPKEY_FORMAT . $this->stepKeys[$stepCount]['stepKey']; + } + } + return $name; + } + + /** + * Return number of passed steps for a test + * + * @param Step $rootStep + * + * @return integer + */ + private function getPassedStepCount($rootStep) + { + $counter = 0; + foreach ($rootStep->getSteps() as $step) { + if (trim($step->getName()) == self::SAVE_SCREENSHOT) { + break; + } + $counter += 1; + } + return $counter; + } } diff --git a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php new file mode 100644 index 000000000..cdfd10bc6 --- /dev/null +++ b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php @@ -0,0 +1,234 @@ +filename = $filename; + $this->method = $method; + $this->load(); + } + + /** + * Load file contents + * + * @return void + */ + private function load() + { + $this->lines = []; + if (!file_exists($this->filename)) { + return; + } + $lines = file($this->filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + if ($lines !== false) { + $this->lines = $lines; + } + $this->beforeSteps = $this->parseStepsForMethod(self::METHOD_BEFORE); + $this->testSteps = $this->parseStepsForMethod("public function " . $this->method); + $this->afterSteps = $this->parseStepsForMethod(self::METHOD_AFTER); + $this->failedSteps[] = $this->parseStepsForFailed(); + $this->stepCount[self::BEFORE_MARK] = count($this->beforeSteps); + $this->stepCount[self::AFTER_MARK] = count($this->afterSteps); + $this->stepCount[self::TEST_MARK] = count($this->testSteps); + $this->stepCount[self::FAILED_MARK] = count($this->failedSteps); + } + + /** + * Return test step actions and step keys based on number of passed steps + * + * @param integer $passedCount + * + * @return array + */ + public function getSteps($passedCount) + { + $steps = []; + $total = $this->stepCount[self::BEFORE_MARK] + + $this->stepCount[self::TEST_MARK] + + $this->stepCount[self::AFTER_MARK]; + if ($passedCount < 0 || $passedCount > $total) { + return $steps; + } + + if ($passedCount == $total) { /* test passed */ + $steps = $this->beforeSteps; + $steps = array_merge($steps, $this->testSteps); + $steps = array_merge($steps, $this->afterSteps); + } elseif ($passedCount < $this->stepCount[self::BEFORE_MARK]) { /* failed in _before() */ + $steps = array_slice($this->beforeSteps, 0, $passedCount); + $steps = array_merge($steps, $this->failedSteps); + $steps = array_merge($steps, $this->afterSteps); + } elseif ($passedCount < ($this->stepCount[self::BEFORE_MARK] + $this->stepCount[self::TEST_MARK])) { /* failed in test() */ + $steps = $this->beforeSteps; + $steps = array_merge( + $steps, + array_slice($this->testSteps, 0, $passedCount - $this->stepCount[self::BEFORE_MARK]) + ); + $steps = array_merge($steps, $this->failedSteps); + $steps = array_merge($steps, $this->afterSteps); + } else { /* failed in _after() */ + $steps = $this->beforeSteps; + $steps = array_merge($steps, $this->testSteps); + $steps = array_merge( + $steps, + array_slice( + $this->afterSteps, + 0, + $passedCount - $this->stepCount[self::BEFORE_MARK] - $this->stepCount[self::TEST_MARK] + ) + ); + $steps = array_merge($steps, $this->failedSteps); + } + return $steps; + } + + /** + * Parse test steps for a method + * + * @param string $method + * + * @return array + */ + private function parseStepsForMethod($method) + { + $process = false; + $steps = []; + foreach ($this->lines as $line) { + if (!$process && strpos($line, $method) !== false) { + $process = true; + } + if ($process && strpos($line, self::METHOD_ENDING) !== false) { + $process = false; + } + if ($process && preg_match(self::REGEX_STEP_KEY, $line, $stepKeys)) { + if (preg_match(self::REGEX_ACTION_NAME, $line, $actions)) { + $steps[] = [ + 'action' => $this->humanize($actions[0]), + 'stepKey' => $stepKeys[0] + ]; + } + } + } + return $steps; + } + + /** + * Parse test steps for failed method + * + * @return array + */ + private function parseStepsForFailed() + { + return [ + 'action' => $this->humanize(self::FAILED_ACTION_NAME), + 'stepKey' => self::FAILED_STEP_KEY + ]; + } + + /** + * Convert input string into human readable words in lower case + * + * @param string $inStr + * + * @return string + */ + private function humanize($inStr) + { + $inStr = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $inStr); + $inStr = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $inStr); + $inStr = preg_replace('~\bdont\b~', 'don\'t', $inStr); + return strtolower($inStr); + } +} diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 07cb96b3a..60fc200a4 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -24,6 +24,7 @@ use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor; use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor; use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil; +use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; /** * Class TestGenerator @@ -39,6 +40,8 @@ class TestGenerator const SUITE_SCOPE = 'suite'; const PRESSKEY_ARRAY_ANCHOR_KEY = '987654321098765432109876543210'; const PERSISTED_OBJECT_NOTATION_REGEX = '/\${1,2}[\w.\[\]]+\${1,2}/'; + const STEPKEY_IN_COMMENT = '//StepKey: '; + const ACTOR = "\$I->"; /** * Path to the export dir. @@ -697,11 +700,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato if (isset($customActionAttributes['storeCode'])) { $storeCode = $customActionAttributes['storeCode']; } + $thisTestSteps = []; switch ($actionObject->getType()) { case "createData": $entity = $customActionAttributes['entity']; //Add an informative statement to help the user debug test runs - $testSteps .= sprintf( + $thisTestSteps[] = sprintf( "\t\t$%s->amGoingTo(\"create entity that has the stepKey: %s\");\n", $actor, $stepKey @@ -746,7 +750,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $createEntityFunctionCall .= ",\n\t\t\t\"{$storeCode}\""; } $createEntityFunctionCall .= "\n\t\t);\n"; - $testSteps .= $createEntityFunctionCall; + $thisTestSteps[] = $createEntityFunctionCall; break; case "deleteData": if (isset($customActionAttributes['createDataKey'])) { @@ -777,8 +781,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $deleteEntityFunctionCall .= "\n\t\t\t\"{$scope}\""; $deleteEntityFunctionCall .= "\n\t\t);\n"; - $testSteps .= $contextSetter; - $testSteps .= $deleteEntityFunctionCall; + $thisTestSteps[] = $contextSetter; + $thisTestSteps[] = $deleteEntityFunctionCall; } else { $url = $this->resolveAllRuntimeReferences([$url])[0]; $url = $this->resolveTestVariable([$url], null)[0]; @@ -787,7 +791,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $actor, $url ); - $testSteps .= $output; + $thisTestSteps[] = $output; } break; case "updateData": @@ -801,7 +805,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $key .= $actionGroup; //Add an informative statement to help the user debug test runs - $testSteps .= sprintf( + $thisTestSteps[] = sprintf( "\t\t$%s->amGoingTo(\"update entity that has the createdDataKey: %s\");\n", $actor, $key @@ -837,7 +841,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $updateEntityFunctionCall .= ",\n\t\t\t\"{$storeCode}\""; } $updateEntityFunctionCall .= "\n\t\t);\n"; - $testSteps .= $updateEntityFunctionCall; + $thisTestSteps[] = $updateEntityFunctionCall; break; case "getData": @@ -847,7 +851,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $index = (int)$customActionAttributes['index']; } //Add an informative statement to help the user debug test runs - $testSteps .= sprintf( + $thisTestSteps[] = sprintf( "\t\t$%s->amGoingTo(\"get entity that has the stepKey: %s\");\n", $actor, $stepKey @@ -889,11 +893,11 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $getEntityFunctionCall .= ",\n\t\t\t{$index}"; } $getEntityFunctionCall .= "\n\t\t);\n"; - $testSteps .= $getEntityFunctionCall; + $thisTestSteps[] = $getEntityFunctionCall; break; case "assertArrayIsSorted": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $parameterArray, @@ -913,11 +917,11 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "typeInPopup": case "dontSee": case "see": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $input, $selector); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $input, $selector); break; case "switchToNextTab": case "switchToPreviousTab": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $input); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $input); break; case "clickWithLeftButton": case "clickWithRightButton": @@ -926,12 +930,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato if (!$selector) { $selector = 'null'; } - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $x, $y); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $selector, $x, $y); break; case "dontSeeCookie": case "resetCookie": case "seeCookie": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $input, @@ -939,7 +943,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "grabCookie": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject, @@ -953,7 +957,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "seeElement": case "seeElementInDOM": case "seeInFormFields": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -965,7 +969,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato if ($parameterArray) { $parameterArray = $this->processPressKey($parameterArray); } - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -975,7 +979,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato break; case "selectOption": case "unselectOption": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -984,7 +988,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "submitForm": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -993,7 +997,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "dragAndDrop": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector1, @@ -1003,7 +1007,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "selectMultipleOptions": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector1, @@ -1013,10 +1017,10 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "executeInSelenium": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $function); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $function); break; case "executeJS": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject, @@ -1025,7 +1029,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato break; case "performOn": case "waitForElementChange": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1034,7 +1038,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "waitForJS": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $function, @@ -1048,11 +1052,11 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "waitForElementNotVisible": case "waitForPwaElementVisible": case "waitForPwaElementNotVisible": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $time); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $selector, $time); break; case "waitForPageLoad": case "waitForText": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $input, @@ -1061,7 +1065,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "formatMoney": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject, @@ -1070,12 +1074,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "mSetLocale": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $input, $locale); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $input, $locale); break; case "grabAttributeFrom": case "grabMultiple": case "grabFromCurrentUrl": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject, @@ -1085,7 +1089,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato break; case "grabTextFrom": case "grabValueFrom": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject, @@ -1093,17 +1097,17 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "grabPageSource": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject ); break; case "resizeWindow": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $width, $height); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $width, $height); break; case "searchAndMultiSelectOption": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1114,10 +1118,10 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato break; case "seeLink": case "dontSeeLink": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $input, $url); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $input, $url); break; case "setCookie": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1141,10 +1145,10 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "loadSessionSnapshot": case "seeInField": case "seeOptionIsSelected": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $selector, $input); break; case "seeNumberOfElements": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1156,10 +1160,10 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "seeInSource": case "dontSeeInSource": // TODO: Need to fix xml parser to allow parsing html. - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $html); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $html); break; case "conditionalClick": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1190,7 +1194,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "assertContains": case "assertNotContains": case "expectException": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $assertExpected, @@ -1205,7 +1209,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $assertExpected = '""'; } - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1222,7 +1226,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "assertNotNull": case "assertNull": case "assertTrue": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $assertActual, @@ -1230,7 +1234,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "assertArraySubset": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $assertExpected, @@ -1240,21 +1244,21 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "fail": - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $assertMessage ); break; case "magentoCLI": - $testSteps .= $this->wrapFunctionCallWithReturnValue( + $thisTestSteps[] = $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, $actionObject, $command, $arguments ); - $testSteps .= sprintf( + $thisTestSteps[] = sprintf( "\t\t$%s->comment(\$%s);\n", $actor, $stepKey @@ -1268,7 +1272,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato )[0]; $argRef = "\t\t\$"; $argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) . "Fields['{$fieldKey}'] = ${input};\n"; - $testSteps .= $argRef; + $thisTestSteps[] = $argRef; break; case "generateDate": $timezone = getenv("DEFAULT_TIMEZONE"); @@ -1281,13 +1285,13 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $dateGenerateCode .= "\t\t\$date->setTimezone(new \DateTimeZone(\"{$timezone}\"));\n"; $dateGenerateCode .= "\t\t\${$stepKey} = \$date->format({$format});\n"; - $testSteps .= $dateGenerateCode; + $thisTestSteps[] = $dateGenerateCode; break; case "skipReadinessCheck": - $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $customActionAttributes['state']); + $thisTestSteps[] = $this->wrapFunctionCall($actor, $actionObject, $customActionAttributes['state']); break; default: - $testSteps .= $this->wrapFunctionCall( + $thisTestSteps[] = $this->wrapFunctionCall( $actor, $actionObject, $selector, @@ -1295,6 +1299,14 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $parameter ); } + foreach ($thisTestSteps as $testStep) { + if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE + && strpos($testStep, self::ACTOR) !== false) { + $testSteps .= rtrim($testStep) . "\t" . self::STEPKEY_IN_COMMENT . $stepKey . "\n"; + } else { + $testSteps .= $testStep; + } + } } return $testSteps; From 1e127245b1d7733d36c0fa1b1a57bf8b87e11523 Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Thu, 23 May 2019 09:53:37 -0500 Subject: [PATCH 2/3] MQE-659: [ALLURE] Include the test "stepKey" in the MFTF Allure Report --- .../Allure/Adapter/MagentoAllureAdapter.php | 2 +- .../Allure/Adapter/MagentoAllureStepKeyReader.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php index 1fb407809..06f690063 100644 --- a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php +++ b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php @@ -267,7 +267,7 @@ public function testStart(TestEvent $testEvent) * Append step key to matching step * * @param integer $stepCount - * @param string $name + * @param string $name * * @return string */ diff --git a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php index cdfd10bc6..104419de1 100644 --- a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php +++ b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureStepKeyReader.php @@ -72,7 +72,6 @@ class MagentoAllureStepKeyReader */ private $afterSteps; - /** * steps in test * @@ -150,8 +149,8 @@ public function getSteps($passedCount) $steps = array_slice($this->beforeSteps, 0, $passedCount); $steps = array_merge($steps, $this->failedSteps); $steps = array_merge($steps, $this->afterSteps); - } elseif ($passedCount < ($this->stepCount[self::BEFORE_MARK] + $this->stepCount[self::TEST_MARK])) { /* failed in test() */ - $steps = $this->beforeSteps; + } elseif ($passedCount < ($this->stepCount[self::BEFORE_MARK] + $this->stepCount[self::TEST_MARK])) { + $steps = $this->beforeSteps; /* failed in test() */ $steps = array_merge( $steps, array_slice($this->testSteps, 0, $passedCount - $this->stepCount[self::BEFORE_MARK]) From a2884ae0c282fe5530c14759fcb966b0fdadd7ab Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Thu, 23 May 2019 16:42:40 -0500 Subject: [PATCH 3/3] MQE-659: [ALLURE] Include the test "stepKey" in the MFTF Allure Report --- .../Allure/Adapter/MagentoAllureAdapter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php index 06f690063..7c90a8c17 100644 --- a/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php +++ b/src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php @@ -250,6 +250,8 @@ function () use ($rootStep, $formattedSteps) { /** * Aggregate to parent method to prepare collecting step keys for a test * + * @param TestEvent $testEvent + * * @return void */ public function testStart(TestEvent $testEvent)