You are here

public function ApigeeEdgeFunctionalJavascriptTestBase::createScreenshot in Apigee Edge 8

Creates a screenshot.

Parameters

string $filename: The file name of the resulting screenshot. If using the default phantomjs driver then this should be a JPG filename.

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.

Overrides WebDriverTestBase::createScreenshot

2 calls to ApigeeEdgeFunctionalJavascriptTestBase::createScreenshot()
AppSettingsFormTest::testAppSettingsForm in tests/src/FunctionalJavascript/AppSettingsFormTest.php
Tests the app settings AJAX form.
DeveloperAppUITest::testCallbackUrlValidationClientSide in tests/src/FunctionalJavascript/DeveloperAppUITest.php
Tests callback url validation on the client-side.

File

tests/src/FunctionalJavascript/ApigeeEdgeFunctionalJavascriptTestBase.php, line 50

Class

ApigeeEdgeFunctionalJavascriptTestBase
Base class for functional javascript tests.

Namespace

Drupal\Tests\apigee_edge\FunctionalJavascript

Code

public function createScreenshot($filename_prefix = '', $set_background_color = TRUE) {
  $log_dir = getenv('APIGEE_EDGE_TEST_LOG_DIR');
  if (!$log_dir) {
    $log_dir = $this->container
      ->get('file_system')
      ->realpath('public://');
  }
  $screenshots_dir = $log_dir . '/screenshots';
  if (!is_dir($screenshots_dir)) {
    mkdir($screenshots_dir, 0777, TRUE);
  }

  /** @var \Drupal\Core\Database\Connection $database */
  $database = $this->container
    ->get('database');
  $test_id = str_replace('test', '', $database
    ->tablePrefix());

  // Add table suffix (test id) to the file name and ensure the generated
  // file name is unique.
  $filename = \Drupal::service('file_system')
    ->createFilename("{$filename_prefix}-{$test_id}.png", $screenshots_dir);

  // Also create a log entry because that way we can understand the state of
  // the system before a screenshot got created more easily from logs.
  $this->container
    ->get('logger.channel.apigee_edge_test')
    ->debug("Creating new screenshot: {$filename}.");
  parent::createScreenshot($filename, $set_background_color);
}