I am testing a angularjs page and using selenium(java) to write automation scripts for the same.
The following is the code that I use for the page synchronization wait before proceeding to next screen action
public static boolean angularHasFinishedProcessing() {
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
driver = GetDriver();//This is to get the driver in current action.
String hasAngularFinishedScript = "var callback = arguments[arguments.length - 1];\n" +
"var el = document.querySelector('html');\n" +
"if (!window.angular) {\n" +
"console.log('1'); \n" +
" callback('false')\n" +
"}\n" +
"if (angular.getTestability) {\n" +
" angular.getTestability(el).whenStable(function(){callback('true')});\n" +
"} else {\n" +
"console.log('hello3'); \n" +
" if (!angular.element(el).injector()) {\n" +
" callback('false')\n" +
" }\n" +
" var browser = angular.element(el).injector().get('$browser');\n" +
" browser.notifyWhenNoOutstandingRequests(function(){callback('true')});\n" +
"}";
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
String isProcessingFinished = javascriptExecutor.executeAsyncScript(hasAngularFinishedScript).toString();
return Boolean.valueOf(isProcessingFinished);
}
};
WebDriverWait wait = new WebDriverWait(driver, 60);
boolean bRet = (wait.until(pageLoadCondition));
if (bRet) {
return bRet;
} else
return false;
}
The issue is isProcessingFinished is always false, the console always writes 1 (meaning window.angular always returns false).
Also, Since, there is no way I can debug the javascript snippet during the execution, I don't know if there is any other issue. Could someone help please?
window.angularpresent when you check it in the console?