Alex Schwartz
Alex Schwartz

Reputation: 85

How to test my selenium/jquery/AJAX project?

I am working on a tiny webapp project using ruby/sinatra. It is displaying a dashboard which is loading its data periodically using AJAX call to the REST API part of the app. (Basically the json results are transformed to some HTML on the page.)

I was driving the development of the REST API and the HTML using RSPec tests, but when I started with AJAX calls I couldn't use TDD.

So, how can I test the result of my javascript/AJAX calls? I would like to examine the resulting HTML.

I would like to avoid to use Selenium with browser to keep the project as lightweight as possible.

Cheers Alex

Upvotes: 2

Views: 725

Answers (1)

Ben Smith
Ben Smith

Reputation: 20230

The MockJax library (for example) will allow you to use TDD for your javascript and jQuery code. It will enable you to mock your AJAX calls, hence allowing you to test your client-side components in isolation.

As for testing the result of the AJAX calls, you could use the Capybara test framework; as well as supporting Selenium (which you want to avoid), it also supports a headless webdriver Capybara-webkit which should be "lighter" than Selenium as it does not load the entire browser.

Upvotes: 1

Related Questions