Skip to content

Instantly share code, notes, and snippets.

@brutuscat
Last active December 18, 2015 22:59
Show Gist options
  • Save brutuscat/5858480 to your computer and use it in GitHub Desktop.
Save brutuscat/5858480 to your computer and use it in GitHub Desktop.
Codeception #waitForAjax helper method
<?php
public function waitForAjax() {
$timeoutMicroSeconds = 2000000;
$isAjaxActive = '
var isAngularAjaxActive = false;
try {
var http = angular.element(".ng-scope").injector().get("$http");
isAngularAjaxActive = !!(http.pendingRequests.length);
}
catch(e) {
isAngularAjaxActive = false;
}
return jQuery.active || isAngularAjaxActive;';
$selenium2 = $this->getModule('Selenium2');
$selenium2->executeInSelenium(
function($session)
use($timeoutMicroSeconds, $isAjaxActive) {
$waiting = 0;
do {
// 1/10th of second
$waiting += 100000;
usleep(100000);
} while ($waiting < $timeoutMicroSeconds &&
$session->execute(['script' => $isAjaxActive, 'args' => []]));
});
}
@clouddueling
Copy link

Was this at any point a codeception test?

@brutuscat
Copy link
Author

No, this is a helper method that you can use in your Acceptance suite instead of the plain "wait"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment