Information Technology Dark Side

Struggles of a Self-Taught Coder

Information Technology Dark Side header image 2

Generating RSpec Tests with Selenium IDE

May 8th, 2008 · 9 Comments

I’ve been using the Selenium IDE as part of my exploratory testing sessions lately, which, if you don’t know, is a testing tool that records my interaction with a web site, allows me to replay it automatically, and also lets me export it as automated tests in various coding languages (Ruby, in my case).

Unfortunately, the format of automated tests I want to create is not supported by the Selenium IDE. The Ruby script it generates is for Unit::Test, not RSpec, which is the format I want. So over the last week I’ve gotten pretty good at generating the Unit::Test code and converting it to RSpec so we can run it in a headless grid integrated with our CI environment.

But I’d rather just export it as RSpec directly and skip the whole conversion process. As it turns out, it’s pretty easy to add a new exporting format to the Selenium IDE. So I did it, by modifying the code that creates Ruby – Unit tests so that it will create RSpec code instead. It only took about ten minutes to do, and the end result isn’t 100% perfect, but for most of the testing I do it will generate RSpec code that will run right the first time.

I know Selenium/RSpec doesn’t have a huge user base at the moment, but if anyone would like to download the file, here it is. I’m not reserving any rights to this – do what you want with it, use at your own risk. To install it, open the Selenium IDE, pick Options=>Options. Click on the formats tab, then the add button. You will see two fields, one tiny, one huge. In the tiny field, type Ruby – RSpec. In the huge field paste the entire contents of the file OVER the pre-populated stuff.

Now, whenever you export a file, Ruby – RSpec will show up as one of your choices. Cool, eh?

If you make improvements to this file, please let me know. I’d like to benefit from them as well. One of the things that would be cool is if I could create describe…do and it…do blocks from the IDE. That would probably require a combination of extensions and changes to the format.

If you enjoyed this post, make sure you subscribe to my RSS feed!
Stumble it!

Tags: Exploratory Testing

9 responses so far ↓

  • 1 carol // Jul 2, 2008 at 11:46 pm

    this is great, thanks for making the converter :-)

  • 2 Sam // Jul 17, 2008 at 1:24 am

    How about importing an rspec selenium test into Selenium IDE? … any chance of that? :)

  • 3 David Christiansen // Jul 17, 2008 at 9:57 am

    Can you tell me a little about why you want to do that? Can’t you just run it with Selenium RC?

  • 4 Sam // Aug 20, 2008 at 9:05 pm

    (Apologies for delayed reaction)
    Just for ease of debugging… It’s so much easier working with HTML tests that can be loaded and stepped through using the Selenium IDE.
    In fact the only reason I want the rspec version is for ease of invocation via a continuous integration server such as Hudson. The spec test version is also good because it allows us to use fixtures for each individual test. To do that with HTML version we need to set up a “fixtures URL” for the HTML test to hit before starting the actual test. Unless you know of a better way to reset the data for a HTML test? :)
    I was actually wondering if it would at all be possible to have the test invoked as rpec (taking advantage of fixtures) but have the rspec test delegate to the HTML test? ie, does the API for the Selenium browser (ruby) allow us to inject HTML test code per chance?

  • 5 IWST Summary | 22 idea street // Oct 3, 2008 at 11:00 am

    […] process, they were written and executed throughout the development lifecycle. He wrote a wrapper to generate RSpec tests from the Selenium IDE, refactored to DRY up the code, and then had the team write their own integration tests as they […]

  • 6 Mike Kelly’s blog » Blog Archive » September IWST: Testers who write code // Oct 7, 2008 at 10:24 am

    […] a domain specific language for their application. As part of his experience report, David shared some code he wrote that takes his Selenium tests and export them to […]

  • 7 Jessie Morris // Jul 21, 2009 at 6:56 pm

    Will there be any sort of update? It doesn't seem to work with 1.0.2… I get "TypeError: EqualsArray.prototype is undefined"

  • 8 kshah // Aug 24, 2009 at 10:06 pm

    Jessie et al:

    Search and replace "EqualsArray" for "seleniumEquals" and your problems should disappear.

    this is per: http://jira.openqa.org/browse/SIDE-250

    Additionally I've integrated Webrat + Selenium + RSpec + The IDE locally, part of that was just switching "@browser" to "selenium" so that Webrat just drops into Selenium mode and you don't need *another* format to run these tests.

    It's not exactly a copy/paste situation, but we'll get there…

  • 9 davidray // Aug 24, 2009 at 10:31 pm

    Thanks! That's awesome.

    Dave

Leave a Comment