> July, 2010 - Vinova - Page 2

Testing for javascript alerts with Cucumber & Capybara

Using Cumcumber + Capybara to run automated testing is a TRENDY now. But you might have trouble finding a way to assert a javascript alert, for e.g. a link created by the link_to … :confirm => “Are you sure?” and similar. Don’t worry, here is a work around to confirm Javascript alert and dialog in your Capybara tests, simply override alert and confirm methods: Given /^I will confirm on next step$/ do begin evaluate_script(“window.alert = function(msg) { return true; }”) evaluate_script(“window.confirm = function(msg) { return true; }”) rescue Capybara::NotSupportedByDriverError end end Rescue here is added in case, you run want to run your tests without javascript (e.g. default capybara driver). If you run feature without javascript simply nothing will happen. Moreover, using this technique you can simulate moving mouse over some elements. It is useful, when you have links that appears when certain div is under the mouse cursor. Then /^I move mouse over “([^”]*)”$/ do |label| begin Capybara.current_session.driver.browser.execute_script(“$(‘#{label}’).mouseover();”) rescue Capybara::NotSupportedByDriverError end end That’s it. Happy testing...
Malcare WordPress Security

graphic designer in singapore,singapore web design,website developer singapore,design firms in singapore,singapore mobile application developer,developers in singapore,singapore mobile app developer,ios developer singapore,web designer singapore,mobile app developer singapore,mobile game developer singapore,web design singapore,mobile apps development singapore,app development singapore,mobile application development singapore,singapore web development,design agency singapore,developer in singapore,mobile app development singapore,website development singapore,website design singapore,web design company singapore,website designer singapore,app developer singapore,android developer singapore,mobile application developer singapore,ruby on rails developer singapore,singapore web design services,web development company singapore,ios app development singapore,web design services singapore,singapore app developer,mobile developer singapore,mobile apps singapore,web development singapore,web application singapore,singapore website design