Skip to content

Commit dc0bf75

Browse files
committed
MQE-1644: Add ability to see JS log in Allure
- Refactor ErrorLogger into BrowserLogUtil, no longer a singleton
1 parent 997a9ef commit dc0bf75

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

src/Magento/FunctionalTestingFramework/Extension/ErrorLogger.php renamed to src/Magento/FunctionalTestingFramework/Extension/BrowserLogUtil.php

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,29 @@
77
namespace Magento\FunctionalTestingFramework\Extension;
88

99
/**
10-
* Class ErrorLogger
10+
* Class BrowserLogUtil
1111
* @package Magento\FunctionalTestingFramework\Extension
1212
*/
13-
class ErrorLogger
13+
class BrowserLogUtil
1414
{
1515
const LOG_TYPE_BROWSER = "browser";
1616
const ERROR_TYPE_JAVASCRIPT = "javascript";
1717

18-
/**
19-
* Error Logger Instance
20-
* @var ErrorLogger
21-
*/
22-
private static $errorLogger;
23-
24-
/**
25-
* Singleton method to return ErrorLogger.
26-
* @return ErrorLogger
27-
*/
28-
public static function getInstance()
29-
{
30-
if (!self::$errorLogger) {
31-
self::$errorLogger = new ErrorLogger();
32-
}
33-
34-
return self::$errorLogger;
35-
}
36-
37-
/**
38-
* ErrorLogger constructor.
39-
*/
40-
private function __construct()
41-
{
42-
// private constructor
43-
}
44-
4518
/**
4619
* Loops through stepEvent for browser log entries
4720
*
4821
* @param \Magento\FunctionalTestingFramework\Module\MagentoWebDriver $module
4922
* @param \Codeception\Event\StepEvent $stepEvent
5023
* @return void
5124
*/
52-
public function logErrors($module, $stepEvent)
25+
public static function logErrors($module, $stepEvent)
5326
{
5427
//Types available should be "server", "browser", "driver". Only care about browser at the moment.
5528
if (in_array(self::LOG_TYPE_BROWSER, $module->webDriver->manage()->getAvailableLogTypes())) {
5629
$browserLogEntries = $module->webDriver->manage()->getLog(self::LOG_TYPE_BROWSER);
57-
$jsErrors = $this->getLogsOfType($browserLogEntries, self::ERROR_TYPE_JAVASCRIPT);
30+
$jsErrors = self::getLogsOfType($browserLogEntries, self::ERROR_TYPE_JAVASCRIPT);
5831
foreach ($jsErrors as $entry) {
59-
$this->logError(self::ERROR_TYPE_JAVASCRIPT, $stepEvent, $entry);
32+
self::logError(self::ERROR_TYPE_JAVASCRIPT, $stepEvent, $entry);
6033
//Set javascript error in MagentoWebDriver internal array
6134
$module->setJsError("ERROR({$entry["level"]}) - " . $entry["message"]);
6235
}
@@ -70,7 +43,7 @@ public function logErrors($module, $stepEvent)
7043
* @param string $type
7144
* @return array
7245
*/
73-
public function getLogsOfType($log, $type)
46+
public static function getLogsOfType($log, $type)
7447
{
7548
$errors = [];
7649
foreach ($log as $entry) {
@@ -88,7 +61,7 @@ public function getLogsOfType($log, $type)
8861
* @param string $type
8962
* @return array
9063
*/
91-
public function filterLogsOfType($log, $type)
64+
public static function filterLogsOfType($log, $type)
9265
{
9366
$errors = [];
9467
foreach ($log as $entry) {
@@ -106,7 +79,7 @@ public function filterLogsOfType($log, $type)
10679
* @param array $entry
10780
* @return void
10881
*/
109-
private function logError($type, $stepEvent, $entry)
82+
private static function logError($type, $stepEvent, $entry)
11083
{
11184
//TODO Add to overall log
11285
$stepEvent->getTest()->getScenario()->comment("{$type} ERROR({$entry["level"]}) - " . $entry["message"]);

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ public function afterStep(\Codeception\Event\StepEvent $e)
177177
if (getenv('ENABLE_BROWSER_LOG')) {
178178
$browserLog = $this->getDriver()->webDriver->manage()->getLog("browser");
179179
foreach (explode(',', getenv('BROWSER_LOG_BLACKLIST')) as $source) {
180-
$browserLog = ErrorLogger::getInstance()->filterLogsOfType($browserLog, $source);
180+
$browserLog = BrowserLogUtil::filterLogsOfType($browserLog, $source);
181181
}
182182

183183
if (!empty($browserLog)) {
184184
AllureHelper::addAttachmentToCurrentStep(json_encode($browserLog, JSON_PRETTY_PRINT), "Browser Log");
185185
}
186186
}
187-
ErrorLogger::getInstance()->logErrors($this->getDriver(), $e);
187+
BrowserLogUtil::logErrors($this->getDriver(), $e);
188188
}
189189

190190
/**

0 commit comments

Comments
 (0)