Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing JavaScript from a Cucumber/Capybara test

It appears that Selenium has a feature called JavascriptExecutor which makes it possible to execute JavaScript directly on the page. However it appears that there is no such thing available to my Cucumber/Capybara tests. How can I execute arbitrary JavaScript from my Cucumber tests?

like image 793
lhahne Avatar asked Jul 19 '11 09:07

lhahne


1 Answers

Capybara has two methods to execute javascript #execute_script and #evaluate_script. Both can be found at: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Selenium/Driver

However, do note that the readme has this statement about the above methods:

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

See http://rubydoc.info/github/jnicklas/capybara/master/file/README.md.

like image 68
kinster Avatar answered Sep 22 '22 08:09

kinster