Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev/tests/functional/standalone_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
defined('WAIT_TIMEOUT') || define('WAIT_TIMEOUT', 30);
$env->setEnvironmentVariable('WAIT_TIMEOUT', WAIT_TIMEOUT);

defined('VERBOSE_ARTIFACTS') || define('VERBOSE_ARTIFACTS', false);
$env->setEnvironmentVariable('VERBOSE_ARTIFACTS', VERBOSE_ARTIFACTS);

try {
new DateTimeZone(DEFAULT_TIMEZONE);
} catch (\Exception $e) {
Expand Down
14 changes: 14 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ Example:
CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE=default
```

### VERBOSE_ARTIFACTS

Determines if passed tests should still have all their Allure artifacts. These artifacts include `.txt` attachments for things like `dontSee` actions and `createData` actions.

If enabled, all tests will have all of their normal Allure artifacts.

If disabled, passed tests will have their Allure artifacts trimmed. Failed tests will still contain all their artifacts.

This is set `false` by default.

```conf
VERBOSE_ARTIFACTS=true
```

### ENABLE_BROWSER_LOG

Enables addition of browser logs to Allure steps
Expand Down
3 changes: 3 additions & 0 deletions etc/config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ MODULE_WHITELIST=Magento_Framework,ConfigurableProductWishlist,ConfigurableProdu
#*** Default timeout for wait actions
#WAIT_TIMEOUT=30

#*** Uncomment and set to enable all tests, regardless of passing status, to have all their Allure artifacts.
#VERBOSE_ARTIFACTS=true

#*** Uncomment and set to enable browser log entries on actions in Allure. Blacklist is used to filter logs of a specific "source"
#ENABLE_BROWSER_LOG=true
#BROWSER_LOG_BLACKLIST=other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
use Magento\FunctionalTestingFramework\Util\TestGenerator;
use Yandex\Allure\Adapter\Model\Failure;
use Yandex\Allure\Adapter\Model\Provider;
use Yandex\Allure\Adapter\Model\Status;
use Yandex\Allure\Adapter\Model\Step;
use Yandex\Allure\Codeception\AllureCodeception;
Expand Down Expand Up @@ -250,13 +252,16 @@ public function testError(FailEvent $failEvent)
*/
public function testEnd()
{
// Peek top of testCaseStorage to check of failure
$testFailed = $this->getLifecycle()->getTestCaseStorage()->get()->getFailure();
// Pops top of stepStorage, need to add it back in after processing
$rootStep = $this->getLifecycle()->getStepStorage()->pollLast();
$formattedSteps = [];
$actionGroupStepContainer = null;

$actionGroupStepKey = null;
foreach ($rootStep->getSteps() as $step) {
$this->removeAttachments($step, $testFailed);
$stepKey = str_replace($actionGroupStepKey, '', $step->getName());
if ($stepKey !== '[]' && $stepKey !== null) {
$step->setName($stepKey);
Expand Down Expand Up @@ -354,4 +359,21 @@ private function retrieveStepKey($stepLine)

return $stepKey;
}

/**
* Removes attachments from step depending on MFTF configuration
* @param Step $step
* @param Failure $testFailed
* @return void
*/
private function removeAttachments($step, $testFailed)
{
//Remove Attachments if verbose flag is not true AND test did not fail
if (getenv('VERBOSE_ARTIFACTS') !== true && $testFailed === null) {
foreach ($step->getAttachments() as $index => $attachment) {
$step->removeAttachment($index);
unlink(Provider::getOutputDirectory() . DIRECTORY_SEPARATOR . $attachment->getSource());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
declare(strict_types=1);

namespace Magento\FunctionalTestingFramework\Console;

Expand All @@ -19,6 +19,14 @@

class GenerateDevUrnCommand extends Command
{
/**
* Argument for the path to IDE config file
*/
const IDE_FILE_PATH_ARGUMENT = 'path';

const PROJECT_PATH_IDENTIFIER = '$PROJECT_DIR$';
const MFTF_SRC_PATH = 'src/Magento/FunctionalTestingFramework/';

/**
* Configures the current command.
*
Expand All @@ -27,8 +35,12 @@ class GenerateDevUrnCommand extends Command
protected function configure()
{
$this->setName('generate:urn-catalog')
->setDescription('This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs.')
->addArgument('path', InputArgument::REQUIRED, 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml)')
->setDescription('Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.')
->addArgument(
self::IDE_FILE_PATH_ARGUMENT,
InputArgument::REQUIRED,
'Path to file to output the catalog. For PhpStorm use .idea/misc.xml'
)
->addOption(
"force",
'f',
Expand All @@ -47,7 +59,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$miscXmlFilePath = $input->getArgument('path') . DIRECTORY_SEPARATOR . "misc.xml";
$miscXmlFilePath = $input->getArgument(self::IDE_FILE_PATH_ARGUMENT);
$miscXmlFile = realpath($miscXmlFilePath);
$force = $input->getOption('force');

Expand All @@ -71,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

//Locate ProjectResources node, create one if none are found.
$nodeForWork = null;
foreach($dom->getElementsByTagName('component') as $child) {
foreach ($dom->getElementsByTagName('component') as $child) {
if ($child->getAttribute('name') === 'ProjectResources') {
$nodeForWork = $child;
}
Expand Down Expand Up @@ -109,35 +121,74 @@ protected function execute(InputInterface $input, OutputInterface $output)

/**
* Generates urn => location array for all MFTF schema.
*
* @return array
* @throws TestFrameworkException
*/
private function generateResourcesArray()
{
$resourcesArray = [
'urn:magento:mftf:DataGenerator/etc/dataOperation.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd'),
$this->getResourcePath('DataGenerator/etc/dataOperation.xsd'),
'urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd'),
$this->getResourcePath('DataGenerator/etc/dataProfileSchema.xsd'),
'urn:magento:mftf:Page/etc/PageObject.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd'),
$this->getResourcePath('Page/etc/PageObject.xsd'),
'urn:magento:mftf:Page/etc/SectionObject.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd'),
$this->getResourcePath('Page/etc/SectionObject.xsd'),
'urn:magento:mftf:Test/etc/actionGroupSchema.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd'),
$this->getResourcePath('Test/etc/actionGroupSchema.xsd'),
'urn:magento:mftf:Test/etc/testSchema.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd'),
$this->getResourcePath('Test/etc/testSchema.xsd'),
'urn:magento:mftf:Suite/etc/suiteSchema.xsd' =>
realpath(FilePathFormatter::format(FW_BP)
. 'src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd')
$this->getResourcePath('Suite/etc/suiteSchema.xsd')
];
return $resourcesArray;
}

/**
* Returns path (full or PhpStorm project-based) to XSD file
*
* @param $relativePath
* @return string
* @throws TestFrameworkException
*/
private function getResourcePath($relativePath)
{
$urnPath = realpath(FilePathFormatter::format(FW_BP) . self::MFTF_SRC_PATH . $relativePath);
$projectRoot = $this->getProjectRootPath();

if ($projectRoot !== null) {
return str_replace($projectRoot, self::PROJECT_PATH_IDENTIFIER, $urnPath);
}

return $urnPath;
}

/**
* Returns Project root directory absolute path
* @TODO Find out how to detect other types of installation
*
* @return string|null
*/
private function getProjectRootPath()
{
$frameworkRoot = realpath(__DIR__);

if ($this->isInstalledByComposer($frameworkRoot)) {
return strstr($frameworkRoot, '/vendor/', true);
}

return null;
}

/**
* Determines whether MFTF was installed using Composer
*
* @param string $frameworkRoot
* @return bool
*/
private function isInstalledByComposer($frameworkRoot)
{
return false !== strpos($frameworkRoot, '/vendor/');
}
}
3 changes: 3 additions & 0 deletions src/Magento/FunctionalTestingFramework/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
defined('WAIT_TIMEOUT') || define('WAIT_TIMEOUT', 30);
$env->setEnvironmentVariable('WAIT_TIMEOUT', WAIT_TIMEOUT);

defined('VERBOSE_ARTIFACTS') || define('VERBOSE_ARTIFACTS', false);
$env->setEnvironmentVariable('VERBOSE_ARTIFACTS', VERBOSE_ARTIFACTS);

try {
new DateTimeZone(DEFAULT_TIMEZONE);
} catch (\Exception $e) {
Expand Down