function WebDriverTestBase::getDrupalSettings

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings()
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings()
  3. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings()

Gets the current Drupal javascript settings and parses into an array.

Unlike BrowserTestBase::getDrupalSettings(), this implementation reads the current values of drupalSettings, capturing all changes made via javascript after the page was loaded.

Return value

array The Drupal javascript settings array.

See also

\Drupal\Tests\BrowserTestBase::getDrupalSettings()

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 getDrupalSettings() {
  $script = <<<EndOfScript
  (function () {
    if (typeof drupalSettings !== 'undefined') {
      return drupalSettings;
    }
  })();
  EndOfScript;
  return $this->getSession()
    ->evaluateScript($script) ?: [];
}

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