Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 Capybara jQuery is not defined

I keep on getting this error:

 Failure/Error: page.evaluate_script('jQuery.active') == 0
 Selenium::WebDriver::Error::JavascriptError:
   ReferenceError: jQuery is not defined

whenever I use the script:

wait_until do
  page.evaluate_script('jQuery.active') == 0
end

I've put in a debugger and checked for the jQuery library. It was existing on the particular page.

Is there something I need to configure for this to work?

EDIT:

Versions of Capybara and RSpec are:

rspec-rails-2.11.0 rspec-2.11.0 capybara-1.1.2

like image 640
Teej Avatar asked Oct 17 '12 07:10

Teej


2 Answers

I ran into the same issue. I solved it by dropping a binding.pry in the test and stopping the selenium browser. Upon inspection, I noticed that the js console had thrown errors: Selenium could not find a .js file.

The root of the problem was an outdated rails test application preloaded with spring. I had installed a gem (moment-timezone-rails) but was still continuing to run my tests with 'spring rspec,' which didn't have the proper directory to find the js file.

restarting spring fixed the problem.

like image 114
Mickey Sheu Avatar answered Nov 19 '22 16:11

Mickey Sheu


The error implies your example does have js:true, but it would be good to post a complete example here.

I found that switching from the default selenium driver to webkit solved a few different issues for me, and also examples run much faster.

Not an answer, per se, but it's worth trying to see if it solves your particular issue.

like image 41
pduey Avatar answered Nov 19 '22 16:11

pduey