|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\FunctionalTestingFramework\Extension; |
| 8 | + |
| 9 | +/** |
| 10 | + * Class ErrorLogger |
| 11 | + * @package Magento\FunctionalTestingFramework\Extension |
| 12 | + */ |
| 13 | +class ErrorLogger |
| 14 | +{ |
| 15 | + /** |
| 16 | + * Error Logger Instance |
| 17 | + * @var ErrorLogger |
| 18 | + */ |
| 19 | + private static $errorLogger; |
| 20 | + |
| 21 | + /** |
| 22 | + * Singleton method to return ErrorLogger. |
| 23 | + * @return ErrorLogger |
| 24 | + */ |
| 25 | + public static function getInstance() |
| 26 | + { |
| 27 | + if (!self::$errorLogger) { |
| 28 | + self::$errorLogger = new ErrorLogger(); |
| 29 | + } |
| 30 | + |
| 31 | + return self::$errorLogger; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * ErrorLogger constructor. |
| 36 | + */ |
| 37 | + private function __construct() |
| 38 | + { |
| 39 | + // private constructor |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Loops through stepEvent for browser log entries |
| 44 | + * @param \Facebook\WebDriver\Remote\RemoteWebDriver $webDriver |
| 45 | + * @param \Codeception\Event\StepEvent $stepEvent |
| 46 | + * @return void |
| 47 | + */ |
| 48 | + public function logErrors($webDriver, $stepEvent) |
| 49 | + { |
| 50 | + //Types available should be "server", "browser", "driver". Only care about browser at the moment. |
| 51 | + $browserLogEntries = $webDriver->manage()->getLog("browser"); |
| 52 | + foreach ($browserLogEntries as $entry) { |
| 53 | + if ($entry["source"] === "javascript") { |
| 54 | + $this->logError("javascript", $stepEvent, $entry); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Logs errors to console/report. |
| 61 | + * @param string $type |
| 62 | + * @param \Codeception\Event\StepEvent $stepEvent |
| 63 | + * @param array $entry |
| 64 | + * @return void |
| 65 | + */ |
| 66 | + private function logError($type, $stepEvent, $entry) |
| 67 | + { |
| 68 | + //TODO Add to overall log |
| 69 | + $stepEvent->getTest()->getScenario()->comment("{$type} ERROR({$entry["level"]}) - " . $entry["message"]); |
| 70 | + } |
| 71 | +} |
0 commit comments