function WebDriverTestBase::createScreenshot

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php \Drupal\FunctionalJavascriptTests\WebDriverTestBase::createScreenshot()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php \Drupal\FunctionalJavascriptTests\WebDriverTestBase::createScreenshot()
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php \Drupal\FunctionalJavascriptTests\WebDriverTestBase::createScreenshot()

Creates a screenshot.

Parameters

string $filename: The file name of the resulting screenshot including a writable path. For example, /tmp/test_screenshot.jpg.

bool $set_background_color: (optional) By default this method will set the background color to white. Set to FALSE to override this behavior.

Throws

\Behat\Mink\Exception\UnsupportedDriverActionException When operation not supported by the driver.

\Behat\Mink\Exception\DriverException When the operation cannot be done.

1 call to WebDriverTestBase::createScreenshot()
BrowserWithJavascriptTest::testCreateScreenshot in core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
Tests creating screenshots.

File

core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php, line 204

Class

WebDriverTestBase
Runs a browser test using a driver that supports JavaScript.

Namespace

Drupal\FunctionalJavascriptTests

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.