Skip to content

Commit

Permalink
fix: screenshot on error feature (#417)
Browse files Browse the repository at this point in the history
* fix: screenshot on error feature

* update changelog
  • Loading branch information
dunglas committed Feb 3, 2021
1 parent 622613b commit d129434
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

1.0.1
-----

* Fix storing screenshots in the wrong directory when `PANTHER_ERROR_SCREENSHOT_DIR` is enabled

1.0.0
-----

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ The following environment variables can be set to change some Panther's behaviou
* `PANTHER_WEB_SERVER_ROUTER`: to use a web server router script which is run at the start of each HTTP request
* `PANTHER_EXTERNAL_BASE_URI`: to use an external web server (the PHP built-in web server will not be started)
* `PANTHER_APP_ENV`: to override the `APP_ENV` variable passed to the web server running the PHP app
* `PANTHER_ERROR_SCREENSHOT_DIR`: to set a base directory for your failure/error screenshots (e.g. `./screenshots`)
* `PANTHER_ERROR_SCREENSHOT_DIR`: to set a base directory for your failure/error screenshots (e.g. `./var/error-screenshots`)

### Changing the Hostname and Port of the Built-in Web Server

Expand Down
7 changes: 4 additions & 3 deletions src/ServerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ private static function reset(): void

private function takeScreenshots(string $type, string $test): void
{
if (!($_SERVER['PANTHER_SCREENSHOT_DIR'] ?? false)) {
if (!($_SERVER['PANTHER_ERROR_SCREENSHOT_DIR'] ?? false)) {
return;
}

foreach (self::$registeredClients as $i => $client) {
$client->takeScreenshot(sprintf('%s_%s_%s-%d.png',
(new \DateTime())->format('Y-m-d_H-i-s'),
$client->takeScreenshot(sprintf('%s/%s_%s_%s-%d.png',
$_SERVER['PANTHER_ERROR_SCREENSHOT_DIR'],
date('Y-m-d_H-i-s'),
$type,
strtr($test, ['\\' => '-', ':' => '_']),
$i
Expand Down

0 comments on commit d129434

Please sign in to comment.