Last active
December 18, 2015 22:59
-
-
Save brutuscat/5858480 to your computer and use it in GitHub Desktop.
Codeception #waitForAjax helper method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => []])); | |
}); | |
} |
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
Was this at any point a codeception test?