diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php index ab1c79d..462b5bf 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php @@ -84,4 +84,24 @@ protected function assertJsCondition($condition, $timeout = 1000, $message = '') $this->assertTrue($result, $message); } + /** + * Creates a screenshot. + * + * @param string $filename + * The file name of the resulting screenshot. If using the default phantomjs + * driver then this should be a JPG filename. + * + * @throws \Behat\Mink\Exception\UnsupportedDriverActionException + * When operation not supported by the driver. + * @throws \Behat\Mink\Exception\DriverException + * When the operation cannot be done + */ + protected function createScreenshot($filename) { + $driver = $this->getSession()->getDriver(); + // Ensure the body background is white. + $driver->executeScript("document.body.style.backgroundColor = 'white';"); + $image = $driver->getScreenshot(); + file_put_contents($filename, $image); + } + }