diff options
author | Matt Friedman <maf675@gmail.com> | 2018-10-03 18:50:30 -0700 |
---|---|---|
committer | Matt Friedman <maf675@gmail.com> | 2018-10-03 18:50:30 -0700 |
commit | 253b42372f05f38c57da95fa174eed92d7ff863a (patch) | |
tree | 5c1e1cc05120b1d24fce47ae526798260c477b21 | |
parent | b487a3d9efbefc97aa7562ffbd4fa23577d7a8e8 (diff) | |
download | forums-253b42372f05f38c57da95fa174eed92d7ff863a.tar forums-253b42372f05f38c57da95fa174eed92d7ff863a.tar.gz forums-253b42372f05f38c57da95fa174eed92d7ff863a.tar.bz2 forums-253b42372f05f38c57da95fa174eed92d7ff863a.tar.xz forums-253b42372f05f38c57da95fa174eed92d7ff863a.zip |
[ticket/15824] Add UI test method to wait for AJAX requests
PHPBB3-15824
-rw-r--r-- | tests/test_framework/phpbb_ui_test_case.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index d16ac78c4b..15a1cd375e 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -606,4 +606,37 @@ class phpbb_ui_test_case extends phpbb_test_case $this->getDriver()->takeScreenshot($screenshot); } + + /** + * Wait for AJAX. Should be called after an AJAX action is made. + * + * @param string $framework javascript frameworks jquery|prototype|dojo + * @throws \Facebook\WebDriver\Exception\NoSuchElementException + * @throws \Facebook\WebDriver\Exception\TimeOutException + */ + public function waitForAjax($framework = 'jquery') + { + switch ($framework) + { + case 'jquery': + $code = 'return jQuery.active;'; + break; + case 'prototype': + $code = 'return Ajax.activeRequestCount;'; + break; + case 'dojo': + $code = 'return dojo.io.XMLHTTPTransport.inFlight.length;'; + break; + default: + throw new \RuntimeException('Unsupported framework'); + break; + } + // wait for at most 30s, retry every 2000ms (2s) + $driver = $this->getDriver(); + $driver->wait(30, 2000)->until( + function () use ($driver, $code) { + return !$driver->executeScript($code); + } + ); + } } |