Friday, July 23, 2010

Getting started with Selenium 2.0 and Ruby

Since my previous post about this was a bit trollish, I decided to redo it.
selenium-webdriver with ruby 1.86+ should work out of the box. But with ruby 1.9x and windows you might need too do some tiny troll magic.

Resources:
Ruby installers
Selenium-Webdriver Ruby Bindings
How to fix the msvcrt-ruby18.dll Ruby 1.9 problem

Installing Ruby
If you haven't installed ruby yet, you will need to do so. Head over to http://rubyinstaller.org/downloads/ and grab the one you prefer (I used ruby 1.91). Install it.

Installing the selenium-webdriver gem
After that we need to install the selenium-webdriver gem. Fire up a cmd/terminal. Some systems might force you to do this as an administrator, see Howto start cmd as an Administrator.
On OSX make sure to use sudo, note that you need administration privileges to be able to use sudo.

Windows: gem install selenium-webdriver
OSX and other sudo thingamajig: sudo gem install selenium-webdriver


Try the example:
Now if you want you can try the example at the RubyBindings page.
If this works now, you don't need to do anything more! If you get a popup about msvcrt-ruby18.dll then you need to read on.


Fixing the "msvcrt-ruby18.dll missing" problem:
Windows and Ruby 1.9 only
The problem is in the win32-api dependency, (one of the gems installed). The solution is outlined here.
What you need to do is to rebuild that gem locally, to do that you need to install the devkit from rubyinstaller.org.

Download the devkit at the Rubyinstaller.org download page.
Unpack it into you ruby installation root directory (for me it was C:\Ruby191)

Run the commands detailed in the fix post.
gem uninstall win32-api 
and  then
gem install win32-api --platform=ruby

This should be it, your example should run fine now.

Next post:
Next post will be about "rubyfying" example 2 in the 5 minute getting started guide for Selenium 2.0

2 comments:

  1. I have similar issue.
    I have several ruby gems installed and I manage them with pik. while in ruby186-mswin (old installer) I get the dialog "msvcrt-ruby191 missing" (I also have ruby 192 installed with devkit in a diff location)

    ReplyDelete
  2. Yes, they have also changed the devkit installation since this post was written. Its now separate from the ruby installations.

    ReplyDelete