|
12 | 12 | */
|
13 | 13 | class ErrorLogger
|
14 | 14 | {
|
| 15 | + const LOG_TYPE_BROWSER = "browser"; |
| 16 | + const ERROR_TYPE_JAVASCRIPT = "javascript"; |
| 17 | + |
15 | 18 | /**
|
16 | 19 | * Error Logger Instance
|
17 | 20 | * @var ErrorLogger
|
@@ -49,16 +52,33 @@ private function __construct()
|
49 | 52 | public function logErrors($module, $stepEvent)
|
50 | 53 | {
|
51 | 54 | //Types available should be "server", "browser", "driver". Only care about browser at the moment.
|
52 |
| - if (in_array("browser", $module->webDriver->manage()->getAvailableLogTypes())) { |
53 |
| - $browserLogEntries = $module->webDriver->manage()->getLog("browser"); |
54 |
| - foreach ($browserLogEntries as $entry) { |
55 |
| - if (array_key_exists("source", $entry) && $entry["source"] === "javascript") { |
56 |
| - $this->logError("javascript", $stepEvent, $entry); |
57 |
| - //Set javascript error in MagentoWebDriver internal array |
58 |
| - $module->setJsError("ERROR({$entry["level"]}) - " . $entry["message"]); |
59 |
| - } |
| 55 | + if (in_array(self::LOG_TYPE_BROWSER, $module->webDriver->manage()->getAvailableLogTypes())) { |
| 56 | + $browserLogEntries = $module->webDriver->manage()->getLog(self::LOG_TYPE_BROWSER); |
| 57 | + $jsErrors = $this->getLogsOfType($browserLogEntries, self::ERROR_TYPE_JAVASCRIPT); |
| 58 | + foreach ($jsErrors as $entry) { |
| 59 | + $this->logError(self::ERROR_TYPE_JAVASCRIPT, $stepEvent, $entry); |
| 60 | + //Set javascript error in MagentoWebDriver internal array |
| 61 | + $module->setJsError("ERROR({$entry["level"]}) - " . $entry["message"]); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Loops through given logs and returns entries of the given type. |
| 68 | + * |
| 69 | + * @param array $log |
| 70 | + * @param string $type |
| 71 | + * @return array |
| 72 | + */ |
| 73 | + public function getLogsOfType($log, $type) |
| 74 | + { |
| 75 | + $errors = []; |
| 76 | + foreach ($log as $entry) { |
| 77 | + if (array_key_exists("source", $entry) && $entry["source"] === $type) { |
| 78 | + $errors[] = $entry; |
60 | 79 | }
|
61 | 80 | }
|
| 81 | + return $errors; |
62 | 82 | }
|
63 | 83 |
|
64 | 84 | /**
|
|
0 commit comments