Skip to content
This repository has been archived by the owner on Aug 13, 2018. It is now read-only.

Commit

Permalink
NEW make screenshot path configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
michalochman committed Aug 8, 2012
1 parent 44327ae commit 07eba2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -38,6 +38,11 @@ config file. This `base_url` is used when concatenating URLs by
`SilverStripeContext->joinUrlParts()` method. `admin_url` and `login_url` should not
be changed in general (unless they are not correct)

Optional `screenshot_path` variable is used to store screenshot of a last know state
of a failed step. It defaults to whatever is returned by PHP's `sys_get_temp_dir()`.
Screenshot names within that directory consist of feature file filename and line
number that failed.

# behat.yml
default:
# ...
Expand All @@ -46,6 +51,7 @@ be changed in general (unless they are not correct)
base_url: http://localhost
admin_url: /admin/
login_url: /Security/login
screenshot_path: features/screenshots/

### Configuring extensions

Expand Down
1 change: 1 addition & 0 deletions behat.yml
Expand Up @@ -5,6 +5,7 @@ default:
base_url: http://localhost
admin_url: /admin/
login_url: /Security/login
screenshot_path: features/screenshots/
extensions:
features/extensions/SilverStripeExtension/init.php:
# Behat\SilverStripeExtension\Extension:
Expand Down
17 changes: 16 additions & 1 deletion features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
Expand Up @@ -156,7 +156,22 @@ public function takeScreenshotAfterFailedStep(StepEvent $event)
$feature = $parent->getFeature();
$step = $event->getStep();

$screenshot_path = realpath(sprintf('%s/%s_%d.png', sys_get_temp_dir(), basename($feature->getFile()), $step->getLine()));
if (isset($this->context['screenshot_path'])) {
$screenshot_path = realpath($this->context['screenshot_path']);
} else {
$screenshot_path = realpath(sys_get_temp_dir());
}

if (!is_dir($screenshot_path)) {
file_put_contents('php://stderr', sprintf('"%s" is not valid directory' . PHP_EOL, $this->context['screenshot_path']));
return;
}
if (!is_writable($screenshot_path)) {
file_put_contents('php://stderr', sprintf('"%s" directory is not writable' . PHP_EOL, $screenshot_path));
return;
}

$screenshot_path = sprintf('%s/%s_%d.png', $screenshot_path, basename($feature->getFile()), $step->getLine());
$screenshot = $driver->wdSession->screenshot();
file_put_contents($screenshot_path, base64_decode($screenshot));
file_put_contents('php://stderr', sprintf('Saving screenshot into %s' . PHP_EOL, $screenshot_path));
Expand Down

0 comments on commit 07eba2f

Please sign in to comment.