mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-14 20:50:30 +01:00
[ticket/15824] Add UI test method to wait for AJAX requests
PHPBB3-15824
This commit is contained in:
parent
b487a3d9ef
commit
253b42372f
@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user