From 5e854cd042a84e4123cc519de96df2be218a16b2 Mon Sep 17 00:00:00 2001 From: Tony Rasmussen Date: Sat, 6 Oct 2012 20:24:32 -0700 Subject: [PATCH 1/3] Implements saveScreenshot helper method in MinkContext --- src/Behat/MinkExtension/Context/MinkContext.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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()); + } } From da2e4ca85f862cdb635ac8a7ab626f7d90d30115 Mon Sep 17 00:00:00 2001 From: Tony Rasmussen Date: Sun, 7 Oct 2012 06:47:51 -0700 Subject: [PATCH 2/3] Lowercase boolean --- src/Behat/MinkExtension/Context/MinkContext.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php index 77de9a6..e4a80a3 100644 --- a/src/Behat/MinkExtension/Context/MinkContext.php +++ b/src/Behat/MinkExtension/Context/MinkContext.php @@ -473,9 +473,9 @@ class MinkContext extends RawMinkContext implements TranslatedContextInterface */ public function saveScreenshot($filename = null, $filepath = null) { - // Under Cygwin, uniqid with more_entropy must be set to TRUE. + // 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'); + $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()); } From be9240abe01698b1be245ad86e1f9e1442d28e7c Mon Sep 17 00:00:00 2001 From: Tony Rasmussen Date: Sun, 7 Oct 2012 10:55:25 -0700 Subject: [PATCH 3/3] getScreenshot is now in Session, not Driver --- src/Behat/MinkExtension/Context/MinkContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php index e4a80a3..1a82f01 100644 --- a/src/Behat/MinkExtension/Context/MinkContext.php +++ b/src/Behat/MinkExtension/Context/MinkContext.php @@ -477,6 +477,6 @@ class MinkContext extends RawMinkContext implements TranslatedContextInterface // 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()); + file_put_contents($filepath . '/' . $filename, $this->getSession()->getScreenshot()); } }