Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3.1, capybara-webkit, why page.execute_script fails?

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 ?

like image 384
simo Avatar asked Nov 27 '25 19:11

simo


1 Answers

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

like image 89
Kevin Davis Avatar answered Nov 29 '25 18:11

Kevin Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!