2009-08-21
By Ivo Dancet
Tags:

First post

How odd, a first post that isn't the first post. It is in fact the second and most uninteresting post. The rSquery post was the first one. When I wrote it, we didn't have a blog at all, so I had to put it in a folder and wait till we did. To make it realistic, we've predated the previous post to the time when I effectively wrote it. So this post serves the only cause to inform you about the date this blog takes off ...

Enjoy!

Comments
2009-05-15
By Ivo Dancet

Introducing rSquery

Choosing the red pill and maybe we'll stay in wonderland ... *

red pill

The moment had to come eventually: we are proud to present our first gem, rSquery. A project that aims to reduce the pain involved in writing Selenium tests in rSpec environments for webapps that use jQuery.

The project contains several methods to help you with writing javascript commands for selenium and javascript based tests for Cucumber or maybe even rSpec in projects that use jQuery.

The name is made of the purposes:

  • r - rSpec
  • S - Selenium
  • query - jQuery

History

The project's origin lies in a project I work on at by2.be which makes use of jQuery for most of its tasks. Selenium tests were the only way to test this bugger (as webrat isn't an option to test js actions) and these tests were taking all the speed and fun out of the project. Testing with jquery matchers instead of those provided by selenium sounded very handy and after some hours of frustration we hacked these few lines together and because of the enormous speed enhancements in writing tests I decided to wrap things up in a gem and release them to whoever would like to use jQuery matchers in an easy way to handle tests.

How it works

The source code is so short it should speak for itself but let me explain the concept:

Everything works around a central jQuery matcher you call with 'jquery(matcher)'. If you leave out 'matcher' the matcher returns the whole document.

The matcher must match exactly one element or it will raise an error. This behaviour makes testing easier for me, but I'm still in search of a better idea here. For now it does the job. (If you have ideas, let me know! Or fork the project on github)

You can call methods upon the matched jquery object: wait_for_element(matcher), wait_for_text(text), wait_for_visible, wait_for_invisible.

Other methods will call that same method upon the jquery. Example: jquery("#content").html will call $("#content").html() in the page you're testing and return what that method returns.

Examples

Using the gem in a project with jQuery you can use lines like these inside tests:

Pitfalls

  • rSquery only works if jQuery is activated on the page you test (obviously).
  • rSquery can only do tests that are purely javascript based. Clicking links will not work, use normal Selenium commands for triggering js-less events (just like jQuery itself).

requirements

  • rSpec
  • Cucumber
  • Ruby-Selenium

Image

Image from http://feedingthepuppy.typepad.com/feeding_the_puppy/

Comments
About
This blog is written by Wouter Vancraeynest and Ivo Dancet and is about what we come across while working at our company by2.be, located in Bruges, Belgium. This can be anything related - though sometimes only remotely - to programming, testing, marketing, Ruby, Apple and other things we do and love ...
Recent posts
Optimizing Vim: tab style
haml-js and jammit
VimRoom
Hudson for a Rails3 project
Looking up Rails(3) routes
Horror story, part II
All tags
Jammit - SaaS - Rails - WriteRoom - Haml - rSpec - Vim - Ruby on Rails - rcov - Cucumber - humans - continuous integration - Hudson - Rails3 - testing - rSquery - haml-js - Bundler - rvm - backbone.js - Selenium
rSquery
Some time ago we made rSquery to be able to easily use jQuery matchers in Selenium projects. You may want to check it out on github. By now this project is not in active development anymore but older projects can still profit from it. (We still use it)