2

I'm trying to write some integration tests for my Rails app using Cucumber, with Capybara. The main page of my application, however,d oes not load with any data in it - as soon as the page is loaded, it triggers a javascript that retrieves the data to insert into the page:

jQuery(document).ready(function() {
  pullUpdates();
});

The pullUpdates function lives in my application.js file.

Now, the trick is, if I simply run the application, this works fine. When I run cucumber, it opens the page in Firefox via selenium, but the data never loads. I tried extending the timeout first, so it waits a good thirty seconds now for the data to load - it never does. In fact, I've gone in and looked at the server log, and my javascript never seems to be even making the ajax call.

I found the capybara-firebug gem, next, thinking that perhaps I could just look and see what was happening in javascript on the client side - but it doesn't open firefox when the page opens, so it doesn't catch any of those javascript errors int he first place. I opened the Error console in firefox itself, nad I think htere is errors, but I cannot read them, because they are immediately eaten by selenium's attempts to check if the object it's looking for has shown up yet.

I imagine this is something simple, stupid, and my fault. But, I don't see how to diagnose it - its not hitting the server, the problem is on the client side somewhere. Can I force Capybara to leave the page open after it errors out, so that I can go back and read the error logs? Is there a better way to troubleshoot this?

jasonpgignac
  • 2,296
  • 2
  • 19
  • 26
  • Just to narrow down the issues, can you gist the scenario or an anonymized version of it? Secondly, you are using @javascript right above the scenario, right? – Srdjan Pejic Mar 31 '11 at 19:11
  • I'm using @selenium right above the scenario, actually (or, at the moment, because I was playing with the capybara-firebug gem, I am using @firebug, but the behavior is functionally identical). You can see my cucumber gist at https://gist.github.com/897019 - if you want to see the javascript it's running, it's at: https://gist.github.com/897023 – jasonpgignac Mar 31 '11 at 19:16
  • if you want to leave the page open just do a sleep before your assertion (just remember not to commit it!) – Derek Ekins Apr 01 '11 at 13:41
  • Are you using Rspec or Minitest/TestUnit? Thoughbot's post on waiting for ajax may help in either case, though it's showing the Rspec version https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara – Sia Jun 09 '16 at 21:31

0 Answers0