Skip to content

Commit 02661c3

Browse files
authored
Merge pull request #104 from magento/MQE-957
MQE-957: MFTF Changes to support DEVOPS-2029
2 parents df4db87 + e4c1f25 commit 02661c3

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

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

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

88
use Magento\FunctionalTestingFramework\Data\Argument\Interpreter\NullType;
9+
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
910
use Yandex\Allure\Adapter\AllureAdapter;
1011
use Codeception\Event\SuiteEvent;
1112

@@ -44,7 +45,7 @@ public function suiteBefore(SuiteEvent $suiteEvent)
4445

4546
if ($this->getGroup() != null) {
4647
$suite = $suiteEvent->getSuite();
47-
$suiteName = ($suite->getName()) . "\\" . $this->getGroup();
48+
$suiteName = ($suite->getName()) . "\\" . $this->sanitizeGroupName($this->getGroup());
4849

4950
call_user_func(\Closure::bind(
5051
function () use ($suite, $suiteName) {
@@ -64,4 +65,30 @@ function () use ($suite, $suiteName) {
6465
// call parent function
6566
parent::suiteBefore($changeSuiteEvent);
6667
}
68+
69+
/**
70+
* Function which santizes any group names changed by the framework for execution in order to consolidate reporting.
71+
*
72+
* @param string $group
73+
* @return string
74+
*/
75+
private function sanitizeGroupName($group)
76+
{
77+
$suiteNames = array_keys(SuiteObjectHandler::getInstance()->getAllObjects());
78+
$exactMatch = in_array($group, $suiteNames);
79+
80+
// if this is an existing suite name we dont' need to worry about changing it
81+
if ($exactMatch || strpos($group, "_") === false) {
82+
return $group;
83+
}
84+
85+
// if we can't find this group in the generated suites we have to assume that the group was split for generation
86+
$groupNameSplit = explode("_", $group);
87+
array_pop($groupNameSplit);
88+
$originalName = implode("_", $groupNameSplit);
89+
90+
// confirm our original name is one of the existing suite names otherwise just return the original group name
91+
$originalName = in_array($originalName, $suiteNames) ? $originalName : $group;
92+
return $originalName;
93+
}
6794
}

src/Magento/FunctionalTestingFramework/Suite/views/SuiteClass.mustache

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHand
1717
class {{suiteName}} extends \Codeception\GroupObject
1818
{
1919
public static $group = '{{suiteName}}';
20-
private static $TEST_COUNT = {{testCount}};
21-
private static $CURRENT_TEST_RUN = 0;
20+
private $testCount = {{testCount}};
21+
private $preconditionFailure = null;
22+
private $currentTestRun = 0;
2223
private static $HOOK_EXECUTION_INIT = "\n/******** Beginning execution of {{suiteName}} suite %s block ********/\n";
2324
private static $HOOK_EXECUTION_END = "\n/******** Execution of {{suiteName}} suite %s block complete ********/\n";
2425
{{#var}}
@@ -29,12 +30,26 @@ class {{suiteName}} extends \Codeception\GroupObject
2930
public function _before(\Codeception\Event\TestEvent $e)
3031
{
3132
// increment test count per execution
32-
self::$CURRENT_TEST_RUN++;
33+
$this->currentTestRun++;
34+
$this->executePreConditions();
3335
34-
if (self::$CURRENT_TEST_RUN == 1) {
36+
if ($this->preconditionFailure != null) {
37+
//if our preconditions fail, we need to mark all the tests as incomplete.
38+
$e->getTest()->getMetadata()->setIncomplete($this->preconditionFailure);
39+
}
40+
}
41+
42+
43+
private function executePreConditions()
44+
{
45+
if ($this->currentTestRun == 1) {
3546
print sprintf(self::$HOOK_EXECUTION_INIT, "before");
3647
37-
{{> testActions}}
48+
try {
49+
{{> testActions}}
50+
} catch (\Exception $exception) {
51+
$this->preconditionFailure = $exception->getMessage();
52+
}
3853

3954
print sprintf(self::$HOOK_EXECUTION_END, "before");
4055
}
@@ -44,10 +59,20 @@ class {{suiteName}} extends \Codeception\GroupObject
4459
{{#after}}
4560
public function _after(\Codeception\Event\TestEvent $e)
4661
{
47-
if (self::$CURRENT_TEST_RUN == self::$TEST_COUNT) {
62+
$this->executePostConditions();
63+
}
64+
65+
66+
private function executePostConditions()
67+
{
68+
if ($this->currentTestRun == $this->testCount) {
4869
print sprintf(self::$HOOK_EXECUTION_INIT, "after");
4970
50-
{{> testActions}}
71+
try {
72+
{{> testActions}}
73+
} catch (\Exception $exception) {
74+
print $exception->getMessage();
75+
}
5176

5277
print sprintf(self::$HOOK_EXECUTION_END, "after");
5378
}

src/Magento/FunctionalTestingFramework/Suite/views/partials/testActions.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ if ($webDriver->webDriver != null) {
1010

1111
// initialize the webdriver session
1212
$webDriver->_initializeSession();
13-
14-
// execute user specified actions
1513
{{/webDriverInit}}
1614
{{#webDriverReset}}
15+
1716
// reset configuration and close session
1817
$this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')->_resetConfig();
1918
$webDriver->webDriver->close();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ public function getAnnotations()
132132
*/
133133
public function getHooks()
134134
{
135+
// if this test is skipped we do not want any before/after actions to generate as the tests will not run
136+
if ($this->isSkipped()) {
137+
return [];
138+
}
135139
return $this->hooks;
136140
}
137141

@@ -142,6 +146,11 @@ public function getHooks()
142146
*/
143147
public function getTestActionCount()
144148
{
149+
// a skipped action results in a single skip being appended to the beginning of the test and no execution
150+
if ($this->isSkipped()) {
151+
return 1;
152+
}
153+
145154
$hookActions = 0;
146155
if (array_key_exists('before', $this->hooks)) {
147156
$hookActions += count($this->hooks['before']->getActions());
@@ -152,7 +161,6 @@ public function getTestActionCount()
152161
}
153162

154163
$testActions = count($this->getOrderedActions());
155-
156164
return $hookActions + $testActions;
157165
}
158166

0 commit comments

Comments
 (0)