Commit c4cb804d authored by xjm's avatar xjm

Issue #2702661 by alexpott, nevergone, GoZ, jibran, dawehner, xjm, hgoto,...

Issue #2702661 by alexpott, nevergone, GoZ, jibran, dawehner, xjm, hgoto, droplet: Make it simple to take screenshots whilst using JavascriptTestBase
parent f2b71152
......@@ -53,4 +53,13 @@ public function testAssertJsCondition() {
$this->assertJsCondition($javascript, 100);
}
/**
* Tests creating screenshots.
*/
public function testCreateScreenshot() {
$this->drupalGet('<front>');
$this->createScreenshot('public://screenshot.jpg');
$this->assertFileExists('public://screenshot.jpg');
}
}
......@@ -102,6 +102,30 @@ 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.
* @param bool $set_background_color
* (optional) By default this method will set the background color to white.
* Set to FALSE to override this behaviour.
*
* @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, $set_background_color = TRUE) {
$session = $this->getSession();
if ($set_background_color) {
$session->executeScript("document.body.style.backgroundColor = 'white';");
}
$image = $session->getScreenshot();
file_put_contents($filename, $image);
}
/**
* {@inheritdoc}
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment