Permalink
Browse files

BUG extract take screenshot logic

  • Loading branch information...
1 parent e7132c1 commit 3c952a4f429b8092c0bb6c6787297d44e42bf544 @michalochman committed Aug 13, 2012
Showing with 29 additions and 25 deletions.
  1. +29 −25 features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
@@ -185,36 +185,40 @@ public function handleAjaxTimeout()
public function takeScreenshotAfterFailedStep(StepEvent $event)
{
if (4 === $event->getResult()) {
- $driver = $this->getSession()->getDriver();
- // quit silently when unsupported
- if (!($driver instanceof Selenium2Driver)) {
- return;
- }
+ $this->takeScreenshot($event);
+ }
+ }
- $parent = $event->getLogicalParent();
- $feature = $parent->getFeature();
- $step = $event->getStep();
+ public function takeScreenshot(StepEvent $event) {
+ $driver = $this->getSession()->getDriver();
+ // quit silently when unsupported
+ if (!($driver instanceof Selenium2Driver)) {
+ return;
+ }
- if (isset($this->context['screenshot_path'])) {
- $screenshot_path = realpath($this->context['screenshot_path']);
- } else {
- $screenshot_path = realpath(sys_get_temp_dir());
- }
+ $parent = $event->getLogicalParent();
+ $feature = $parent->getFeature();
+ $step = $event->getStep();
- 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;
- }
+ if (isset($this->context['screenshot_path'])) {
+ $screenshot_path = realpath($this->context['screenshot_path']);
+ } else {
+ $screenshot_path = realpath(sys_get_temp_dir());
+ }
- $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));
+ 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));
}
/**

0 comments on commit 3c952a4

Please sign in to comment.