How to wait on javascript executor call in @Keyword method

Like I suspected, that is ASYNCHRONOUS.

Like I said above, you need to set up a sentinel in the JavaScript code in the AUT. Your Groovy code in Katalon will need to wait for that sentinel to signal the AUT async process is complete.

Please pay attention to this next bit of info - it’s important.

It is far, far easier and more robust to do this without a sentinel approach. It is much better to wait for the state of the AUT to change in some way. That change would signal when the async stuff is completed. Perhaps, for example, a specific text box is filled with certain data. Or perhaps a grid/table appears.

Only if nothing like that happens would you need a sentinel approach.

The best (easiest) way to create the sentinel

Have the developers do it. Tell them to add these functions to the AUT page:

function setSentinel(name, value) {
  window[name] = value;
}
function getSentinel(name) {
 return window[name];
}

If they are unwilling, you can inject them yourself along with each of the following.

Tell them to write something like this before the ajax calls begin:

window.ajax_completed = false;

Again, if they are unwilling, inject it yourself, before the async process begins.

Next you need this to happen at the point where ALL ajax calls have resolved:

window.ajax_completed = true;

Your Groovy code needs to loop while getSentinel("ajax_completed") returns false.

The moment the sentinel returns true…

  1. Break out of the while loop.
  2. (Optional) call setSentinel("ajax_completed", false) so that it’s ready for a possible subsequent call.
  3. Continue with you test case.

Make your Groovy while loop delay for one second – WebUI.delay(1) – between iterations. You should throw an error when 20 or 30 iterations go by without the sentinel returning true. That’s a long time, I think, but only you know the behavior of your AUT.