You are here

protected function JavascriptTestTrait::createScreenshot in Commerce Core 8.2

Creates a screenshot.

Parameters

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.

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

File

tests/src/Traits/JavascriptTestTrait.php, line 83

Class

JavascriptTestTrait
Allows tests using BrowserTest run with Javascript enabled.

Namespace

Drupal\Tests\commerce\Traits

Code

protected function createScreenshot($set_background_color = TRUE) {
  $jpg_output_filename = $this->htmlOutputClassName . '-' . $this->htmlOutputCounter . '-' . $this->htmlOutputTestId . '.jpg';
  $session = $this
    ->getSession();
  if ($set_background_color) {
    $session
      ->executeScript("document.body.style.backgroundColor = 'white';");
  }
  $image = $session
    ->getScreenshot();
  file_put_contents($this->htmlOutputDirectory . '/' . $jpg_output_filename, $image);
  $this->htmlOutputCounter++;
}