Skip to content

Commit 8c0ebee

Browse files
committed
MQE-62:[Spike] Screenshots in Allure
- update MagentoWebDriver to include png and html attachments in allure report
1 parent 684bc07 commit 8c0ebee

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Magento/AcceptanceTestFramework/Module/MagentoWebDriver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace Magento\AcceptanceTestFramework\Module;
33

44
use Codeception\Module\WebDriver;
5+
use Codeception\Test\Descriptor;
6+
use Codeception\TestInterface;
57
use Facebook\WebDriver\WebDriverSelect;
68
use Facebook\WebDriver\WebDriverBy;
79
use Facebook\WebDriver\Exception\NoSuchElementException;
@@ -10,6 +12,7 @@
1012
use Codeception\Exception\ModuleException;
1113
use Codeception\Util\Uri;
1214
use Codeception\Util\ActionSequence;
15+
use Yandex\Allure\Adapter\Support\AttachmentSupport;
1316

1417
/**
1518
* MagentoWebDriver module provides common Magento web actions through Selenium WebDriver.
@@ -31,6 +34,7 @@
3134
*/
3235
class MagentoWebDriver extends WebDriver
3336
{
37+
use AttachmentSupport;
3438
public static $loadingMask = '.loading-mask';
3539

3640
/**
@@ -276,4 +280,23 @@ public function scrollToTopOfPage()
276280
{
277281
$this->executeJS('window.scrollTo(0,0);');
278282
}
283+
284+
/**
285+
* Override for _failed method in Codeception method. Adds png and html attachments to allure report
286+
* following parent execution of test failure processing.
287+
* @param TestInterface $test
288+
* @param \Exception $fail
289+
*/
290+
public function _failed(TestInterface $test, $fail)
291+
{
292+
parent::_failed($test, $fail);
293+
294+
// Reconstruct file naming from codeception method
295+
$filename = preg_replace('~\W~', '.', Descriptor::getTestSignature($test));
296+
$outputDir = codecept_output_dir();
297+
$pngReport = $outputDir . mb_strcut($filename, 0, 245, 'utf-8') . '.fail.png';
298+
$htmlReport = $outputDir . mb_strcut($filename, 0, 244, 'utf-8') . '.fail.html';
299+
$this->addAttachment($pngReport, $test->getMetadata()->getName() . '.png', 'image/png');
300+
$this->addAttachment($htmlReport, $test->getMetadata()->getName() . '.html', 'text/html');
301+
}
279302
}

0 commit comments

Comments
 (0)