5

I have a cucumber scenario tagged with @javascript and i'm testing it with some really basic inline js calls. I'm running this using

Capybara.javascript_driver = :webkit

If i do this on the page, after the element in question (which has id="ajax_test_results", don't worry about the ajax though, for now)

document.getElementById('ajax_test_results').innerHTML = 'Replaced with basic js, ie not jquery, without waiting for pageLoad';  

then it works: if i render out the page in my test i can see that the js has run and updated the content. However, if i try to do the same thing with jquery

jQuery("#ajax_test_results").html("updated with basic jquery dom manipulation, without waiting for document.ready");  

then it doesn't work. I think that jquery isn't being loaded, but i don't know how to go about debugging it.

Any ideas anyone? I saw this post which looked hopeful https://stackoverflow.com/questions/8428405/cucumber-tests-jquery-does-not-loaded-in-webdriver but config.assets.debug = true causes an error for me - i think it's rails 3 only. Is there a rails 2 equivalent? or some other solution?

Grateful for any advice - max

Community
  • 1
  • 1
Max Williams
  • 32,435
  • 31
  • 130
  • 197
  • I have this same problem and it's not clear to me where you would tell cucumber to load jQuery. – bias May 06 '12 at 22:25
  • Could it be that jquery is not loaded YET? – moritz Jun 16 '12 at 16:11
  • 1
    Seems obvious, but you might go about debugging it by calling `sleep` for a couple seconds in between when the page is rendered and you try to test for the element's presence – varatis Jul 03 '12 at 20:48

1 Answers1

0

For debugging you can use console.log('message') or alert statements. It will output your messages to the terminal screen. Also you can use:

Gemfile:
  gem 'debugger'

When /your step/ do
  require 'ruby-debug'
  debugger
end

then you can debug using page.evaluate_script or page.execute_script methods. It's quite easy to do it.

According jquery problem could you try to use $ instead of jQuery?

Alex.

oivoodoo
  • 774
  • 7
  • 23