[Sharing is learning] [Get rewards] Join Us Now to Become Katalon Champions. Learn more
Ismar
Katalon Apprentice
07/11/2018

Wait for ajax requests?

Hello,

Is is possible to wait for ajax requests, like jQuery.post function for example?

Best regards
Ismar
Upvote
Quote

Comments

  • Russ Thomas
    Katalon Evangelist
    07/11/2018
    edited July 11
    There are two Katalon APIs which are meant to aid with ajax, but since they check load state, they may not help much with inline XHR requests:

    https://docs.katalon.com/display/KD/[WebUI]+Wait+For+Angular+Load
    https://docs.katalon.com/display/KD/[WebUI]+Wait+for+jQuery+Load

    However, there is a jQuery internal variable, jQuery.active which you can check.  It is a counter that returns to zero when all jQuery XHR requests are finished.  You can use JavaScript to check its value.

    @Katalon Team there should be a WebUI API that specifically waits for that variable to return to zero.

    Take care that you don't try to check it too soon after whatever event is meant to trigger the XHR request. Add a one second delay prior to checking it using WebUI.delay(1) or similar.

    For reference, here is a link to the jQuery source:
    https://github.com/jquery/jquery/blob/master/src/ajax.js#L579

    Best Answer
    Upvote
    Quote
  • Ismar
    Katalon Apprentice
    07/12/2018
    Thanks Russ. That could work fine. I am just hoping that I don't come across pages don't do ajax requests without jQuery but instead use pure JS (XMLHttpRequest)

    Best regards
    Ismar
    Upvote
    Quote
  • Russ Thomas
    Katalon Evangelist
    07/12/2018
    Sorry, Ismar, I meant to add that to the post -- that it's almost as easy to do it in pure JS. The host will need to implement a counter similar to jQuery.active (XHR.active perhaps).

    Thanks for the BA B)
    Upvote
    Quote
Sign In or Register to comment.
Not the answer you're looking for? Consider subscribing to Business support.