views:

483

answers:

1

I'm using Cumcumber + capybara + selenium to run automated testing, but I'm having trouble finding a way to assert that a javascript alert is displayed.

This question seems has a solution with selenium, but I can't figure out how to call the selenium object using Capybara.

Is there a simple way to test for alerts using Capybara? Or is there a workaround?

A: 

I've tried to do it, but Capybara doesn't support it. Capybara comes with Selenium 2.0, not Selenium RC (as stated in the page), which is the library that supports that method.

Using it with Cucumber outside of Capybara involves loading and initializing the selenium-client driver. I assume you are using it within the context of Rails, so it will require setting up the environment, I'm not sure how much work is this, but I'd say is not worth the hassle.

If your concern are the alerts created by the link_to ... :confirm => "Are you sure?" and similar, don't worry, Cucumber provides a nice workaround for those with some pseudo-js emulation.

Chubas
Thanks. Just for anyone else with the same problem, I ended up using the work around on this page: http://stackoverflow.com/questions/2458632/how-to-test-a-confirm-dialog-with-cucumber
Dhruv