diff --git a/src/ChromeDriver.php b/src/ChromeDriver.php index a877fd9..daecdf6 100644 --- a/src/ChromeDriver.php +++ b/src/ChromeDriver.php @@ -185,8 +185,7 @@ public function reset() STDOUT, "ERROR: Could not reset - ".$e->getMessage()."\n".$e->getTraceAsString() ); - $l = new ChromeDriverDebugLogger; - $l->logDriverException($e, 'Failed to reset'); + ChromeDriverDebugLogger::instance()->logDriverException($e, 'Failed to reset'); // What happens if we just allow the scenario to continue here???? } } diff --git a/src/ChromeDriverDebugLogger.php b/src/ChromeDriverDebugLogger.php index 80852c5..680938c 100644 --- a/src/ChromeDriverDebugLogger.php +++ b/src/ChromeDriverDebugLogger.php @@ -9,6 +9,19 @@ class ChromeDriverDebugLogger { + private $scenario_id = 0; + + private $page_ready = NULL; + + public static function instance(): ChromeDriverDebugLogger + { + static $instance; + if ( ! $instance) { + $instance = new static; + } + + return $instance; + } public function __construct() { @@ -74,10 +87,12 @@ private function writeLog(array $vars) } $now = new \DateTimeImmutable; - $vars = array_merge( + $vars = array_merge( [ - '@' => ($now)->format('H:i:s.u'), - '+ms' => round(DateTimeDiff::microsBetween($last_logged, $now) / 1000, 3), + '@' => ($now)->format('H:i:s.u'), + '+ms' => round(DateTimeDiff::microsBetween($last_logged, $now) / 1000, 3), + 'scenario' => $this->scenario_id, + 'page_ready' => $this->page_ready, ], $vars ); @@ -113,6 +128,28 @@ public function logPageReadyStateChange(bool $state, string $change_trigger) 'trigger' => $change_trigger, ] ); + $this->page_ready = $state; + } + + public function beginScenario(string $file, string $line) + { + $this->scenario_id++; + $this->writeLog( + [ + 'action' => 'beginScenario', + 'scenarioName' => $file.':'.$line, + ] + ); + } + + public function endScenario(bool $is_passed) + { + $this->writeLog( + [ + 'action' => 'endScenario', + 'result' => $is_passed, + ] + ); } private function nameConnection(DevToolsConnection $connection) diff --git a/src/DevToolsConnection.php b/src/DevToolsConnection.php index 80956d6..a286f07 100644 --- a/src/DevToolsConnection.php +++ b/src/DevToolsConnection.php @@ -22,7 +22,7 @@ public function __construct($url, $socket_timeout = null) { $this->url = $url; $this->socket_timeout = $socket_timeout; - $this->logger = new ChromeDriverDebugLogger; + $this->logger = ChromeDriverDebugLogger::instance(); } public function canDevToolsConnectionBeEstablished()