Working in an inherited automation codebase. There is a method which waits to see if jQuery has been initialized.
.until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver webDriver) {
boolean go = (Long) runJavaScript("return jQuery.active") == 0;
if (!go) {
LOGGER.debug("stalling");
}
return go;
}
Ran into an issue with jQuery not being defined. I added a check to see if jQuery is defined and refactored the code to use a lambda expression
.until((Function<WebDriver, Boolean>) webDriver -> {
boolean go = (Boolean) runJavaScript("return !!window.jQuery && jQuery.active == 0");
if(!go){
LOGGER.debug("stalling");
}
return go;
});
My question pertains to the casting of the return of runJavaScript
which is just a custom wrapper of JavaScriptExecutor's executeScript
method. Initially it was built to return jQuery.active
cast it to a Long
and compare it to zero. I refactored it to cast the return of jQuery.active == 0
to a boolean
. Is there any value to cast to a Long
over a boolean
in this case?