You are here

protected function WebDriverTestBase::createScreenshot in Drupal 9

Same name and namespace in other branches
  1. 8 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 176

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