function AdminUiTest::getAjaxResponseCount

Gets the Drupal AJAX response count observed on this page.

Return value

int The number of completed XHR requests observed since the page was loaded.

1 call to AdminUiTest::getAjaxResponseCount()
AdminUiTest::testSettingsOnlyFireAjaxWithCkeditor5 in core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php
Confirm settings only trigger AJAX when select value is CKEditor 5.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php, line 92

Class

AdminUiTest
Tests for CKEditor 5 in the admin UI.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

protected function getAjaxResponseCount() : int {
  // Half a second should suffice for any of the test's DOM interactions to
  // have triggered an AJAX request, if any.
  try {
    $this->assertSession()
      ->assertWaitOnAjaxRequest(500);
  } catch (\RuntimeException $e) {
    throw new \LogicException('An AJAX request was still being processed, this suggests a assertWaitOnAjaxRequest() call is missing.');
  }
  // Now that there definitely is no more AJAX request in progress, count the
  // number of AJAX responses.
  $javascript = <<<JS
(function(){
  return window.performance
    .getEntries()
    .filter(entry => entry.initiatorType === 'xmlhttprequest' && entry.name.indexOf('_wrapper_format=drupal_ajax') !== -1)
    .length
})()
JS;
  return $this->getSession()
    ->evaluateScript($javascript);
}

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