What is the best way to do integration testing for javascript heavy interface in rails application?

We have a web application that makes extensive use of AJAXy Javascript in the user interface. We have almost complete coverage of our backend code using Shoulda and Webrat, and we would like to expand our test suite to include full integration testing through the Javascript UI.

We tried Selenium, but found it fragile and temperamental. Are there any more reliable options?

UPDATE

For those who are still checking this out, we have finished using Xvfb so that we can run Firefox without a screen. Lets us run the test on the Jenkins CI headless server. We still need to periodically test "live" locally to debug, but it works very well.

+6
javascript ruby-on-rails ruby-on-rails-3
source share
5 answers

Hmm, I would look at Capybara, it can use selenium-webdriver (not to be confused with selenium-RC, they are different) for testing javascript. I did not find it very fragile compared to Webrat ... it seems pretty consistent.

As Chris Rueber says, there really aren't any headless DOM interpreters that support JS - for now, it launches a web browser for your automation or writes unit tests in javascript itself (which is not really integration testing either).

When you have many tests for selenium-webdriver-backed, they may take some time to work sometimes, but this is certainly better than no tests at all.

+1
source share

One of the JavaScript gurus I've been working on recently has pointed out PhantomJS as an interesting tool for testing our web applications that work with JavaScript. We haven't tried it yet, but the idea of ​​decapitating WebKit for DOM testing seems promising to me.

+3
source share

This is something I've been struggling with for a while, as I do some work with ExtJS (a very powerful JavaScript browser interface) and Rails.

After exploring several options. I still have not found the perfect solution for this. Ideally, I could run them headless and just report the exit. Unfortunately, none of the emulators there seem to be able to easily run JavaScript with full DOM support (at least not one of the options I found). Thus, to a large extent, this means that you need to run the full JavaScript code in a real interpreter (for example, in a browser). Webrat with Selenium works reasonably well, assuming you're ready to handle the pain by trying to properly handle your user interface requests. If this is your own JavaScript with which you implement it, it might be easier. But when it comes to a third-party user interface library, for which you do not have much control, it can certainly get, let's say, interesting.

This is probably not the most helpful answer, but these have been my results so far!

+2
source share

check gem jasminerice to check your js logic.

https://github.com/bradphelan/jasminerice

for an integration test, I would recommend using rspec with capybara as acceptance tests. distinguish between query specifications and acceptance specifications! Another possibility is to use turnips as an alternative to cucumber.

https://github.com/jnicklas/turnip

to speed up testing of headless tests. You can use capybara-webkit (qt dependent) or poltergeist (which depends on phantomjs). both are easily customizable. I prefer poltergeist.

+1
source share

There are some gems you could use if you didn't like Selenium.

I recommend Jasmine : https://github.com/pivotal/jasmine

You can also check Culerity : https://github.com/langalex/culerity

0
source share

All Articles