Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

NEW make screenshot path configurable

  • Loading branch information...
commit 07eba2f6c1a3e8e43459e61e91dd6d574c7023a4 1 parent 44327ae
@michalochman authored
View
6 README.md
@@ -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:
# ...
@@ -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
View
1  behat.yml
@@ -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:
View
17 features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.