Skip to content

Commit b79ec06

Browse files
authored
Merge pull request #676 from magento/MQE-2082-Rebase
MQE-2086: Reduce amount of attachments in Allure reports
2 parents bbab15d + b13598e commit b79ec06

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

dev/tests/functional/standalone_bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
defined('WAIT_TIMEOUT') || define('WAIT_TIMEOUT', 30);
5454
$env->setEnvironmentVariable('WAIT_TIMEOUT', WAIT_TIMEOUT);
5555

56+
defined('VERBOSE_ARTIFACTS') || define('VERBOSE_ARTIFACTS', false);
57+
$env->setEnvironmentVariable('VERBOSE_ARTIFACTS', VERBOSE_ARTIFACTS);
58+
5659
try {
5760
new DateTimeZone(DEFAULT_TIMEZONE);
5861
} catch (\Exception $e) {

docs/configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,20 @@ Example:
299299
CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE=default
300300
```
301301

302+
### VERBOSE_ARTIFACTS
303+
304+
Determines if passed tests should still have all their Allure artifacts. These artifacts include `.txt` attachments for `dontSee` actions and `createData` actions.
305+
306+
If enabled, all tests will have all of their normal Allure artifacts.
307+
308+
If disabled, passed tests will have their Allure artifacts trimmed. Failed tests will still contain all their artifacts.
309+
310+
This is set `false` by default.
311+
312+
```conf
313+
VERBOSE_ARTIFACTS=true
314+
```
315+
302316
### ENABLE_BROWSER_LOG
303317

304318
Enables addition of browser logs to Allure steps

etc/config/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ MODULE_WHITELIST=Magento_Framework,ConfigurableProductWishlist,ConfigurableProdu
5959
#*** Default timeout for wait actions
6060
#WAIT_TIMEOUT=30
6161

62+
#*** Uncomment and set to enable all tests, regardless of passing status, to have all their Allure artifacts.
63+
#VERBOSE_ARTIFACTS=true
64+
6265
#*** Uncomment and set to enable browser log entries on actions in Allure. Blacklist is used to filter logs of a specific "source"
6366
#ENABLE_BROWSER_LOG=true
6467
#BROWSER_LOG_BLACKLIST=other

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
1313
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1414
use Magento\FunctionalTestingFramework\Util\TestGenerator;
15+
use Yandex\Allure\Adapter\Model\Failure;
16+
use Yandex\Allure\Adapter\Model\Provider;
1517
use Yandex\Allure\Adapter\Model\Status;
1618
use Yandex\Allure\Adapter\Model\Step;
1719
use Yandex\Allure\Adapter\Allure;
@@ -256,13 +258,16 @@ public function testError(FailEvent $failEvent)
256258
*/
257259
public function testEnd(TestEvent $testEvent)
258260
{
261+
// Peek top of testCaseStorage to check of failure
262+
$testFailed = $this->getLifecycle()->getTestCaseStorage()->get()->getFailure();
259263
// Pops top of stepStorage, need to add it back in after processing
260264
$rootStep = $this->getLifecycle()->getStepStorage()->pollLast();
261265
$formattedSteps = [];
262266
$actionGroupStepContainer = null;
263267

264268
$actionGroupStepKey = null;
265269
foreach ($rootStep->getSteps() as $step) {
270+
$this->removeAttachments($step, $testFailed);
266271
$stepKey = str_replace($actionGroupStepKey, '', $step->getName());
267272
if ($stepKey !== '[]' && $stepKey !== null) {
268273
$step->setName($stepKey);
@@ -379,4 +384,21 @@ private function retrieveStepKey($stepLine)
379384

380385
return $stepKey;
381386
}
387+
388+
/**
389+
* Removes attachments from step depending on MFTF configuration
390+
* @param Step $step
391+
* @param Failure $testFailed
392+
* @return void
393+
*/
394+
private function removeAttachments($step, $testFailed)
395+
{
396+
//Remove Attachments if verbose flag is not true AND test did not fail
397+
if (getenv('VERBOSE_ARTIFACTS') !== true && $testFailed === null) {
398+
foreach ($step->getAttachments() as $index => $attachment) {
399+
$step->removeAttachment($index);
400+
unlink(Provider::getOutputDirectory() . DIRECTORY_SEPARATOR . $attachment->getSource());
401+
}
402+
}
403+
}
382404
}

src/Magento/FunctionalTestingFramework/_bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
defined('WAIT_TIMEOUT') || define('WAIT_TIMEOUT', 30);
5454
$env->setEnvironmentVariable('WAIT_TIMEOUT', WAIT_TIMEOUT);
5555

56+
defined('VERBOSE_ARTIFACTS') || define('VERBOSE_ARTIFACTS', false);
57+
$env->setEnvironmentVariable('VERBOSE_ARTIFACTS', VERBOSE_ARTIFACTS);
58+
5659
try {
5760
new DateTimeZone(DEFAULT_TIMEZONE);
5861
} catch (\Exception $e) {

0 commit comments

Comments
 (0)