3
votes

After installing capybara-webkit, I tried to try a test inside a spec, here is my test:

Capybara.default_driver = :webkit

page.execute_script("$('#submit_direction').attr('value', '1');$('#quizForm').submit()")

Then, I get this error:

/home/sam/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:136: warning: Insecure world writable dir /home/sam/Documents/RoR in PATH, mode 040777 undefined|0|ReferenceError: Can't find variable: $

Capybara::Driver::Webkit::WebkitInvalidResponseError: Javascript failed to execute

Any idea please ?

1
Could you provide more details for your step? I think you can see issue for this step because of undefined jQuery on the page in the moment when you try to run this step. May be you should make it on window load event.oivoodoo

1 Answers

8
votes

I'm guessing the capybara-webkit JS driver is a bit dodgy.

From the capybara github page:

For simple expressions, you can return the result of the script. Note that this may break with more complicated expressions:

result = page.evaluate_script('4 + 4');

However, from the code you have there, it looks like you can do quite a few things with Capybara itself.

$('#submit_direction').attr('value', '1')

could be replaced with:

page.find("#submit_direction").set('1')

and

$('#quizForm').submit()

could be replaced with:

page.click_on('quizForm')

see the capybara docs on capybara actions