Skip to content

Commit 39d987a

Browse files
committed
MQE-1644: Add ability to see JS log in Allure
- Moved redundant logic
1 parent 2b8710b commit 39d987a

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/Magento/FunctionalTestingFramework/Extension/BrowserLogUtil.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@ class BrowserLogUtil
1616
const ERROR_TYPE_JAVASCRIPT = "javascript";
1717

1818
/**
19-
* Loops through stepEvent for browser log entries
19+
* Loops throw errors in log and logs them to allure. Uses Module to set the error itself
2020
*
21-
* @param \Magento\FunctionalTestingFramework\Module\MagentoWebDriver $module
22-
* @param \Codeception\Event\StepEvent $stepEvent
21+
* @param array $log
22+
* @param \Codeception\Module\WebDriver $module
23+
* @param \Codeception\Event\StepEvent $stepEvent
2324
* @return void
2425
*/
25-
public static function logErrors($module, $stepEvent)
26+
public static function logErrors($log, $module, $stepEvent)
2627
{
27-
//Types available should be "server", "browser", "driver". Only care about browser at the moment.
28-
if (in_array(self::LOG_TYPE_BROWSER, $module->webDriver->manage()->getAvailableLogTypes())) {
29-
$browserLogEntries = $module->webDriver->manage()->getLog(self::LOG_TYPE_BROWSER);
30-
$jsErrors = self::getLogsOfType($browserLogEntries, self::ERROR_TYPE_JAVASCRIPT);
31-
foreach ($jsErrors as $entry) {
32-
self::logError(self::ERROR_TYPE_JAVASCRIPT, $stepEvent, $entry);
33-
//Set javascript error in MagentoWebDriver internal array
34-
$module->setJsError("ERROR({$entry["level"]}) - " . $entry["message"]);
35-
}
28+
$jsErrors = self::getLogsOfType($log, self::ERROR_TYPE_JAVASCRIPT);
29+
foreach ($jsErrors as $entry) {
30+
self::logError(self::ERROR_TYPE_JAVASCRIPT, $stepEvent, $entry);
31+
//Set javascript error in MagentoWebDriver internal array
32+
$module->setJsError("ERROR({$entry["level"]}) - " . $entry["message"]);
3633
}
3734
}
3835

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,16 @@ public function beforeStep(\Codeception\Event\StepEvent $e)
174174
*/
175175
public function afterStep(\Codeception\Event\StepEvent $e)
176176
{
177+
$browserLog = $this->getDriver()->webDriver->manage()->getLog("browser");
177178
if (getenv('ENABLE_BROWSER_LOG')) {
178-
$browserLog = $this->getDriver()->webDriver->manage()->getLog("browser");
179179
foreach (explode(',', getenv('BROWSER_LOG_BLACKLIST')) as $source) {
180180
$browserLog = BrowserLogUtil::filterLogsOfType($browserLog, $source);
181181
}
182-
183182
if (!empty($browserLog)) {
184183
AllureHelper::addAttachmentToCurrentStep(json_encode($browserLog, JSON_PRETTY_PRINT), "Browser Log");
185184
}
186185
}
187-
BrowserLogUtil::logErrors($this->getDriver(), $e);
186+
BrowserLogUtil::logErrors($browserLog, $this->getDriver(), $e);
188187
}
189188

190189
/**

0 commit comments

Comments
 (0)