Waiting for jQuery Ajax calls to finish in Cucumber

May 4, 2011 Mike Gehard

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.

About the Author


How Cloud Foundry Works When a New Application is Deployed
How Cloud Foundry Works When a New Application is Deployed

Previously in this blog post, we covered how the client side does a vmc push to deploy an application onto ...

The Cloud Foundry Community
The Cloud Foundry Community

The reaction to Cloud Foundry from the developer community since it was launched three weeks ago has been i...

SpringOne 2022

Register Now