-
Notifications
You must be signed in to change notification settings - Fork 132
MQE-1644: Add ability to see JS log in Allure #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36a243a
MQE-1644: Add ability to see JS log in Allure
KevinBKozan 997a9ef
MQE-1644: Add ability to see JS log in Allure
KevinBKozan dc0bf75
MQE-1644: Add ability to see JS log in Allure
KevinBKozan 31073a3
MQE-1644: Add ability to see JS log in Allure
KevinBKozan d7d14c3
MQE-1644: Add ability to see JS log in Allure
KevinBKozan 2b8710b
Merge branch 'develop' into MQE-1644
KevinBKozan 39d987a
MQE-1644: Add ability to see JS log in Allure
KevinBKozan ac6daba
Merge branch 'develop' into MQE-1644
KevinBKozan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
dev/tests/unit/Magento/FunctionalTestFramework/Extension/BrowserLogUtilTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace tests\unit\Magento\FunctionalTestFramework\Extension; | ||
|
||
use Magento\FunctionalTestingFramework\Util\MagentoTestCase; | ||
use Magento\FunctionalTestingFramework\Extension\BrowserLogUtil; | ||
|
||
class BrowserLogUtilTest extends MagentoTestCase | ||
{ | ||
public function testGetLogsOfType() | ||
{ | ||
$entryOne = [ | ||
"level" => "WARNING", | ||
"message" => "warningMessage", | ||
"source" => "console-api", | ||
"timestamp" => 1234567890 | ||
]; | ||
$entryTwo = [ | ||
"level" => "ERROR", | ||
"message" => "errorMessage", | ||
"source" => "other", | ||
"timestamp" => 1234567890 | ||
]; | ||
$entryThree = [ | ||
"level" => "LOG", | ||
"message" => "logMessage", | ||
"source" => "javascript", | ||
"timestamp" => 1234567890 | ||
]; | ||
$log = [ | ||
$entryOne, | ||
$entryTwo, | ||
$entryThree | ||
]; | ||
|
||
$actual = BrowserLogUtil::getLogsOfType($log, 'console-api'); | ||
|
||
self::assertEquals($entryOne, $actual[0]); | ||
} | ||
|
||
public function testFilterLogsOfType() | ||
{ | ||
$entryOne = [ | ||
"level" => "WARNING", | ||
"message" => "warningMessage", | ||
"source" => "console-api", | ||
"timestamp" => 1234567890 | ||
]; | ||
$entryTwo = [ | ||
"level" => "ERROR", | ||
"message" => "errorMessage", | ||
"source" => "other", | ||
"timestamp" => 1234567890 | ||
]; | ||
$entryThree = [ | ||
"level" => "LOG", | ||
"message" => "logMessage", | ||
"source" => "javascript", | ||
"timestamp" => 1234567890 | ||
]; | ||
$log = [ | ||
$entryOne, | ||
$entryTwo, | ||
$entryThree | ||
]; | ||
|
||
$actual = BrowserLogUtil::filterLogsOfType($log, 'console-api'); | ||
|
||
self::assertEquals($entryTwo, $actual[0]); | ||
self::assertEquals($entryThree, $actual[1]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/Magento/FunctionalTestingFramework/Extension/BrowserLogUtil.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\FunctionalTestingFramework\Extension; | ||
|
||
/** | ||
* Class BrowserLogUtil | ||
* @package Magento\FunctionalTestingFramework\Extension | ||
*/ | ||
class BrowserLogUtil | ||
{ | ||
const LOG_TYPE_BROWSER = "browser"; | ||
const ERROR_TYPE_JAVASCRIPT = "javascript"; | ||
|
||
/** | ||
* Loops throw errors in log and logs them to allure. Uses Module to set the error itself | ||
* | ||
* @param array $log | ||
* @param \Codeception\Module\WebDriver $module | ||
* @param \Codeception\Event\StepEvent $stepEvent | ||
* @return void | ||
*/ | ||
public static function logErrors($log, $module, $stepEvent) | ||
{ | ||
$jsErrors = self::getLogsOfType($log, self::ERROR_TYPE_JAVASCRIPT); | ||
foreach ($jsErrors as $entry) { | ||
self::logError(self::ERROR_TYPE_JAVASCRIPT, $stepEvent, $entry); | ||
//Set javascript error in MagentoWebDriver internal array | ||
$module->setJsError("ERROR({$entry["level"]}) - " . $entry["message"]); | ||
} | ||
} | ||
|
||
/** | ||
* Loops through given log and returns entries of the given type. | ||
* | ||
* @param array $log | ||
* @param string $type | ||
* @return array | ||
*/ | ||
public static function getLogsOfType($log, $type) | ||
{ | ||
$errors = []; | ||
foreach ($log as $entry) { | ||
if (array_key_exists("source", $entry) && $entry["source"] === $type) { | ||
$errors[] = $entry; | ||
} | ||
} | ||
return $errors; | ||
} | ||
|
||
/** | ||
* Loops through given log and filters entries of the given type. | ||
* | ||
* @param array $log | ||
* @param string $type | ||
* @return array | ||
*/ | ||
public static function filterLogsOfType($log, $type) | ||
jilu1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$errors = []; | ||
foreach ($log as $entry) { | ||
if (array_key_exists("source", $entry) && $entry["source"] !== $type) { | ||
$errors[] = $entry; | ||
} | ||
} | ||
return $errors; | ||
} | ||
|
||
/** | ||
* Logs errors to console/report. | ||
* @param string $type | ||
* @param \Codeception\Event\StepEvent $stepEvent | ||
* @param array $entry | ||
* @return void | ||
*/ | ||
private static function logError($type, $stepEvent, $entry) | ||
{ | ||
//TODO Add to overall log | ||
$stepEvent->getTest()->getScenario()->comment("{$type} ERROR({$entry["level"]}) - " . $entry["message"]); | ||
} | ||
} |
76 changes: 0 additions & 76 deletions
76
src/Magento/FunctionalTestingFramework/Extension/ErrorLogger.php
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.