MDL-43439: Behat - new $CFG param - behat_screenshot_after_failure
authorDamyon Wiese <damyon@moodle.com>
Wed, 18 Dec 2013 08:13:46 +0000 (16:13 +0800)
committerDavid Monllao <davidm@moodle.com>
Fri, 10 Jan 2014 09:54:53 +0000 (17:54 +0800)
lib/tests/behat/behat_hooks.php

index 2478e78..430ed4f 100644 (file)
@@ -278,6 +278,21 @@ class behat_hooks extends behat_base {
         }
     }
 
+    /**
+     * Take screenshot when step fails.
+     * Screenshot is saved at /tmp/
+     *
+     * @AfterStep
+     */
+    public function take_screenshot_after_failed_step(Behat\Behat\Event\StepEvent $event) {
+        global $CFG;
+
+        if (!empty($CFG->behat_screenshot_after_failure) &&
+                $event->getResult() === Behat\Behat\Event\StepEvent::FAILED) {
+            $this->saveScreenshot();
+        }
+    }
+
     /**
      * Waits for all the JS to be loaded.
      *