|
8 | 8 |
|
9 | 9 | use Codeception\Events;
|
10 | 10 | use Codeception\Step;
|
| 11 | +use Codeception\Test\Test; |
11 | 12 | use Magento\FunctionalTestingFramework\Allure\AllureHelper;
|
12 | 13 | use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
|
| 14 | +use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler; |
13 | 15 | use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
|
14 | 16 | use Qameta\Allure\Allure;
|
| 17 | +use Qameta\Allure\AllureLifecycleInterface; |
15 | 18 | use Qameta\Allure\Model\StepResult;
|
16 | 19 | use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
|
17 | 20 | use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
|
@@ -158,6 +161,68 @@ function (TestResult $testResult) {
|
158 | 161 | $this->getFormattedSteps($testResult);
|
159 | 162 | }
|
160 | 163 | );
|
| 164 | + |
| 165 | + $this->addTestsInSuites($lifecycle, $cest); |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Function to add test under the suites. |
| 170 | + * |
| 171 | + * @param object $lifecycle |
| 172 | + * @param object $cest |
| 173 | + * |
| 174 | + * @return void |
| 175 | + */ |
| 176 | + private function addTestsInSuites($lifecycle, $cest): void |
| 177 | + { |
| 178 | + $groupName = null; |
| 179 | + if ($this->options['groups'] !== null) { |
| 180 | + $group = $this->options['groups'][0]; |
| 181 | + $groupName = $this->sanitizeGroupName($group); |
| 182 | + } |
| 183 | + $lifecycle->updateTest( |
| 184 | + function (TestResult $testResult) use ($groupName, $cest) { |
| 185 | + $labels = $testResult->getLabels(); |
| 186 | + foreach ($labels as $label) { |
| 187 | + if ($groupName !== null && $label->getName() === "parentSuite") { |
| 188 | + $label->setValue(sprintf('%s\%s', $label->getValue(), $groupName)); |
| 189 | + } |
| 190 | + if ($label->getName() === "package") { |
| 191 | + $className = $cest->getReportFields()['class']; |
| 192 | + $className = preg_replace('{_[0-9]*_G}', '', $className); |
| 193 | + $label->setValue($className); |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + ); |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * Function which santizes any group names changed by the framework for execution in order to consolidate reporting. |
| 202 | + * |
| 203 | + * @param string $group |
| 204 | + * @return string |
| 205 | + */ |
| 206 | + private function sanitizeGroupName($group): string |
| 207 | + { |
| 208 | + $suiteNames = array_keys(SuiteObjectHandler::getInstance()->getAllObjects()); |
| 209 | + $exactMatch = in_array($group, $suiteNames); |
| 210 | + |
| 211 | + // if this is an existing suite name we dont' need to worry about changing it |
| 212 | + if ($exactMatch || strpos($group, "_") === false) { |
| 213 | + return $group; |
| 214 | + } |
| 215 | + |
| 216 | + // if we can't find this group in the generated suites we have to assume that the group was split for generation |
| 217 | + $groupNameSplit = explode("_", $group); |
| 218 | + array_pop($groupNameSplit); |
| 219 | + array_pop($groupNameSplit); |
| 220 | + $originalName = implode("_", $groupNameSplit); |
| 221 | + |
| 222 | + // confirm our original name is one of the existing suite names otherwise just return the original group name |
| 223 | + $originalName = in_array($originalName, $suiteNames) ? $originalName : $group; |
| 224 | + |
| 225 | + return $originalName; |
161 | 226 | }
|
162 | 227 |
|
163 | 228 | /**
|
|
0 commit comments