From 143504967ddc9ffff88ecc54dcb1df164f5a16e5 Mon Sep 17 00:00:00 2001 From: Alexander Horvath Date: Fri, 11 Oct 2024 23:39:11 +0200 Subject: [PATCH] check for directory existence when storing console log or storing source, if it does not exist create it --- src/Browser.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Browser.php b/src/Browser.php index 637d13381..fd98ccdb0 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -484,8 +484,16 @@ public function storeConsoleLog($name) $console = $this->driver->manage()->getLog('browser'); if (! empty($console)) { + $filePath = sprintf('%s/%s.log', rtrim(static::$storeConsoleLogAt, '/'), $name); + + $directoryPath = dirname($filePath); + + if (! is_dir($directoryPath)) { + mkdir($directoryPath, 0777, true); + } + file_put_contents( - sprintf('%s/%s.log', rtrim(static::$storeConsoleLogAt, '/'), $name), json_encode($console, JSON_PRETTY_PRINT) + $filePath, json_encode($console, JSON_PRETTY_PRINT) ); } } @@ -504,9 +512,15 @@ public function storeSource($name) $source = $this->driver->getPageSource(); if (! empty($source)) { - file_put_contents( - sprintf('%s/%s.txt', rtrim(static::$storeSourceAt, '/'), $name), $source - ); + $filePath = sprintf('%s/%s.txt', rtrim(static::$storeSourceAt, '/'), $name); + + $directoryPath = dirname($filePath); + + if (! is_dir($directoryPath)) { + mkdir($directoryPath, 0777, true); + } + + file_put_contents($filePath, $source); } return $this;