-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathBrowserLogUtil.php
84 lines (78 loc) · 2.41 KB
/
BrowserLogUtil.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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)
{
$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"]);
}
}