Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
Waiting for jQuery Ajax calls to finish in Cucumber

You may be asking yourself why you’d want to do this in the first place. Well here’s why I would want to do it.

We had some Webdriver based Cucumber tests that passed fine locally but kept failing on our CI box. Our CI box is a bit underpowered at the moment so I thought what might be happening is that our tests weren’t waiting long enough for the Ajaxy stuff to happen because the Ajax responses were taking a long time.

After some poking around in the source code of jQuery, I found the $.active property. This property keeps track of the number of active Ajax requests that are going on and I thought this might help us out.

What I came up with was this gist:

I added this step right after my Cucumber step that caused the Ajax call so that Cucumber would wait to move on until I knew that everything was done.

This step solved our CI failures and all was good in our test suite again.

  1. Peter Lyons says:

    Thanks, Mike, great tip. I was just implementing similar logic in my async jasmine tests. This works great for that as well.

  2. Darrin says:

    Not sure if you’re using capybara, but the post was categorized as such…anyway capybara does/will do this for you.

  3. Mike Gehard says:

    @Darrin…good to know. Yes I am using Capybara but it didn’t seem to do the trick without this step. I’ll experiment a little bit and see if I can figure out why.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *

Share This