Skip to content

Commit 83dab03

Browse files
committed
MQE-957: MFTF Changes to support DEVOPS-2029
- add new skipped logic to TestObject - update Group Object file generation to include try/catch
1 parent df4db87 commit 83dab03

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
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/partials/testActions.mustache

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ if ($webDriver->webDriver != null) {
1010

1111
// initialize the webdriver session
1212
$webDriver->_initializeSession();
13-
14-
// execute user specified actions
13+
try {
14+
// execute user specified actions
1515
{{/webDriverInit}}
1616
{{#webDriverReset}}
17+
} catch (\Exception $e) {
18+
print $e->getMessage();
19+
}
20+
1721
// reset configuration and close session
1822
$this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')->_resetConfig();
1923
$webDriver->webDriver->close();
2024
$webDriver->webDriver = null;
2125
{{/webDriverReset}}
2226
{{#action}}
23-
{{{action}}}
27+
{{{action}}}
2428
{{/action}}
2529
{{#createData}}
2630
${{entityName}} = DataObjectHandler::getInstance()->getObject("{{entityName}}");

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)