mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/15824] Add UI test method to wait for AJAX requests
PHPBB3-15824
This commit is contained in:
parent
b487a3d9ef
commit
253b42372f
1 changed files with 33 additions and 0 deletions
|
@ -606,4 +606,37 @@ class phpbb_ui_test_case extends phpbb_test_case
|
||||||
|
|
||||||
$this->getDriver()->takeScreenshot($screenshot);
|
$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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue