Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Tools
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Waiting for jQuery Ajax calls to finish in Cucumber

Mike Gehard
Tuesday, May 3, 2011

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.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

3 Comments

  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.

    May 3, 2011 at 7:51 pm

  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.

    https://github.com/jnicklas/capybara/commit/021b87f6ba512f9903b209178c584def45d62e7f

    May 4, 2011 at 5:30 am

  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.

    May 5, 2011 at 6:20 pm

Add New Comment Cancel reply

Your email address will not be published.

Mike Gehard

Mike Gehard
Boulder

Recent Posts

  • Using Jasmine to test CoffeeScript in a Rails 3.1 App
  • Mocking Fog when using it with Carrierwave
  • Making sure you implement the ActiveModel interface fully
Subscribe to Mike's Feed

Author Topics

coffeescript (1)
rails3 (10)
capybara (6)
cucumber (12)
javascript (2)
jquery (1)
webdriver (5)
carrierwave (1)
fog (1)
s3 (2)
testing (1)
rspec2 (3)
omniauth (1)
ruby (5)
devise (1)
aruba (2)
generators (2)
solr (1)
sunspot (1)
concerns (1)
mixins (1)
resque (1)
thin (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Tools
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >