diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php index c29de8c..77de9a6 100644 --- a/src/Behat/MinkExtension/Context/MinkContext.php +++ b/src/Behat/MinkExtension/Context/MinkContext.php @@ -462,4 +462,21 @@ class MinkContext extends RawMinkContext implements TranslatedContextInterface { return str_replace('\\"', '"', $argument); } + + /** + * Save a screenshot of the current window to the file system. + * + * @param string $filename Desired filename, defaults to + * __.png + * @param string $filepath Desired filepath, defaults to + * upload_tmp_dir, falls back to sys_get_temp_dir() + */ + public function saveScreenshot($filename = null, $filepath = null) + { + // Under Cygwin, uniqid with more_entropy must be set to TRUE. + // No effect in other environments. + $filename = $filename ?: sprintf('%s_%s_%s.%s', $this->getMinkParameter('browser_name'), date('c'), uniqid('', TRUE), 'png'); + $filepath = $filepath ? $filepath : ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); + file_put_contents($filepath . '/' . $filename, $this->getSession()->getDriver()->getScreenshot()); + } }