Skip to content

Commit

Permalink
check for directory existence when storing console log or storing sou…
Browse files Browse the repository at this point in the history
…rce, if it does not exist create it
  • Loading branch information
Alexander Horvath committed Oct 11, 2024
1 parent 0a88da6 commit 1435049
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 1435049

Please sign in to comment.