Saturday, August 19, 2006

Ruby $LOAD_PATH Watir

{

On and off I've been messing around trying to get Watir to work on my machine. The gem installed properly based on the instructions given to simple go to the command line and use the following:

gem install watir

But when I tried to execute a simple test I got the following:

uninitialized constant Watir
./watir.rb:6
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
C:/CODE06/RubyStart/WatirTest.rb:7
./watir.rb:6: uninitialized constant Watir (NameError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
from C:/CODE06/RubyStart/WatirTest.rb:7

It seemed like an environment variable was not properly referencing the library but when I hunted for it I saw no environment variables. I ran the unit tests for Watir and it seemed to have installed correctly but I noticed the following at the beginning of each:

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__

Smells like a path the the library so I investigated with:

puts $LOAD_PATH

which shows me the following:

c:/ruby/lib/ruby/site_ruby/1.8
c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt
c:/ruby/lib/ruby/site_ruby
c:/ruby/lib/ruby/1.8
c:/ruby/lib/ruby/1.8/i386-mswin32

In order to get the script working I just hacked the $LOAD_PATH to include a hardcoded reference to my Watir libraries:

$LOAD_PATH.unshift 'c:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1'

From there I was set with the following simple script:

require 'watir'

include Watir

ie = Watir::IE.new
ie.goto("http://www.t3rse.com")

I'll dig into this - I haven't had the patience to sit down with a Ruby book just yet (anyone have ideas?) but if anyone has a similar problem running Watir, here is a hack to get you started if this is a hit on your Google search.

}

2 comments:

Mordechai said...

Thanks a lot for this hack. I spent a good 2 hours wondering what the heck I was doing wrong.

Much appreciated.
Mordechai

Erpheus said...

Thank you, I've alredy spent a lot of time looking for the solution.