public function iWaitForAjaxToFinish($event = null)
    {
        $condition = <<<JS
    (function() {
      function isAjaxing(instance) {
        return instance && instance.ajaxing === true;
      }
      var d7_not_ajaxing = true;
      if (typeof Drupal !== 'undefined' && typeof Drupal.ajax !== 'undefined' && typeof Drupal.ajax.instances === 'undefined') {
        for(var i in Drupal.ajax) { if (isAjaxing(Drupal.ajax[i])) { d7_not_ajaxing = false; } }
      }
      var d8_not_ajaxing = (typeof Drupal === 'undefined' || typeof Drupal.ajax === 'undefined' || typeof Drupal.ajax.instances === 'undefined' || !Drupal.ajax.instances.some(isAjaxing))
      return (
        // Assert no AJAX request is running (via jQuery or Drupal) and no
        // animation is running.
        (typeof jQuery === 'undefined' || (jQuery.active === 0 && jQuery(':animated').length === 0)) &&
        d7_not_ajaxing && d8_not_ajaxing
      );
    }());
JS;
        $ajax_timeout = $this->getMinkParameter('ajax_timeout');
        $result = $this->getSession()->wait(1000 * $ajax_timeout, $condition);
        if (!$result) {
            if ($ajax_timeout === null) {
                throw new \Exception('No AJAX timeout has been defined. Please verify that "Drupal\MinkExtension" is configured in behat.yml (and not "Behat\MinkExtension").');
            }
            if ($event) {
                /** @var \Behat\Behat\Hook\Scope\BeforeStepScope $event */
                $event_data = ' ' . json_encode([
                    'name' => $event->getName(),
                    'feature' => $event->getFeature()->getTitle(),
                    'step' => $event->getStep()->getText(),
                    'suite' => $event->getSuite()->getName(),
                ]);
            } else {
                $event_data = '';
            }
            throw new \RuntimeException('Unable to complete AJAX request.' . $event_data);
        }
    }