JSWebAssert.php 895 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests;
  3. use Drupal\Tests\WebAssert;
  4. /**
  5. * Defines a class with methods for asserting presence of elements during tests.
  6. */
  7. class JSWebAssert extends WebAssert {
  8. /**
  9. * Waits for AJAX request to be completed.
  10. *
  11. * @param int $timeout
  12. * (Optional) Timeout in milliseconds, defaults to 10000.
  13. * @param string $message
  14. * (optional) A message for exception.
  15. *
  16. * @throws \RuntimeException
  17. * When the request is not completed. If left blank, a default message will
  18. * be displayed.
  19. */
  20. public function assertWaitOnAjaxRequest($timeout = 10000, $message = 'Unable to complete AJAX request.') {
  21. $result = $this->session->wait($timeout, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))');
  22. if (!$result) {
  23. throw new \RuntimeException($message);
  24. }
  25. }
  26. }