Skip to content

Commit 997a9ef

Browse files
committed
MQE-1644: Add ability to see JS log in Allure
- Addec blacklist - Renamed variables
1 parent 36a243a commit 997a9ef

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

etc/config/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ MODULE_WHITELIST=Magento_Framework,ConfigurableProductWishlist,ConfigurableProdu
5454

5555
#*** Default timeout for wait actions
5656
#WAIT_TIMEOUT=10
57+
58+
#*** Uncomment and set to enable browser log entries on actions in Allure. Blacklist is used to filter logs of a specific "source"
59+
#ENABLE_BROWSER_LOG=true
60+
#BROWSER_LOG_BLACKLIST=other
61+
5762
#*** End of .env ***#

src/Magento/FunctionalTestingFramework/Extension/ErrorLogger.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function logErrors($module, $stepEvent)
6464
}
6565

6666
/**
67-
* Loops through given logs and returns entries of the given type.
67+
* Loops through given log and returns entries of the given type.
6868
*
6969
* @param array $log
7070
* @param string $type
@@ -81,6 +81,24 @@ public function getLogsOfType($log, $type)
8181
return $errors;
8282
}
8383

84+
/**
85+
* Loops through given log and filters entries of the given type.
86+
*
87+
* @param array $log
88+
* @param string $type
89+
* @return array
90+
*/
91+
public function filterLogsOfType($log, $type)
92+
{
93+
$errors = [];
94+
foreach ($log as $entry) {
95+
if (array_key_exists("source", $entry) && $entry["source"] !== $type) {
96+
$errors[] = $entry;
97+
}
98+
}
99+
return $errors;
100+
}
101+
84102
/**
85103
* Logs errors to console/report.
86104
* @param string $type

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,14 @@ public function beforeStep(\Codeception\Event\StepEvent $e)
174174
*/
175175
public function afterStep(\Codeception\Event\StepEvent $e)
176176
{
177-
if (getenv('ENABLE_JS_LOG')) {
178-
$browserLogEntries = $this->getDriver()->webDriver->manage()->getLog("browser");
179-
$jsErrors = ErrorLogger::getInstance()->getLogsOfType($browserLogEntries, ErrorLogger::ERROR_TYPE_JAVASCRIPT);
180-
if (!empty($jsErrors)) {
181-
AllureHelper::addAttachmentToCurrentStep($jsErrors);
177+
if (getenv('ENABLE_BROWSER_LOG')) {
178+
$browserLog = $this->getDriver()->webDriver->manage()->getLog("browser");
179+
foreach (explode(',', getenv('BROWSER_LOG_BLACKLIST')) as $source) {
180+
$browserLog = ErrorLogger::getInstance()->filterLogsOfType($browserLog, $source);
181+
}
182+
183+
if (!empty($browserLog)) {
184+
AllureHelper::addAttachmentToCurrentStep(json_encode($browserLog, JSON_PRETTY_PRINT), "Browser Log");
182185
}
183186
}
184187
ErrorLogger::getInstance()->logErrors($this->getDriver(), $e);

0 commit comments

Comments
 (0)