Wednesday, December 15, 2010

LoadError: no such file to load -- watir

For you web developers who need to write good, coded regression tests, Watir is an excellent choice. 
As quoted from the Watir website:

Watir, pronounced water, is an open-source (BSD) family of Ruby libraries for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.
Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.
An awesome tool, no doubt about it.  It saves us heaps of time on regression testing (our tester is a little inexperienced), load testing, and trying out new stuff and making sure all is running well.  
However, you might encounter a problem when trying to run up their Quick Start Tutorial or their examples.  When you attempt to run anything from the irb or from a ruby script with the following statement:
require "watir"
You get the following error back:
LoadError: no such file to load -- watir

C:\>irb
irb(main):001:0> require 'watir'
LoadError: no such file to load -- watir
from (irb):1:in `require'
from (irb):1
irb(main):002:0> exit
You can now make sure watir is installed and the version of ruby with the following commands:

C:\>gem list --local watir
*** LOCAL GEMS ***
watir (1.6.7)

C:\>ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]

The fix is simple.  You need to load rubygems first.

C:\>irb
irb(main):001:0> require 'watir'
LoadError: no such file to load -- watir
from (irb):1:in `require'
from (irb):1
irb(main):002:0> require 'rubygems'
=3D> true
irb(main):003:0> require 'watir'
=3D> true 
irb(main):004:0>
 

If this helps you, you owe me a beer.

3 comments:

  1. can you help me this procedure doesn't resolve the issue

    ReplyDelete
  2. C:\Ruby187\lib\ruby\gems\1.8\gems\watir-2.0.1\unittests>gem list --local watir

    *** LOCAL GEMS ***

    watir (2.0.1)

    C:\Ruby187\lib\ruby\gems\1.8\gems\watir-2.0.1\unittests>
    C:\Ruby187\lib\ruby\gems\1.8\gems\watir-2.0.1\unittests>ruby -v
    ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]

    C:\Ruby187\lib\ruby\gems\1.8\gems\watir-2.0.1\unittests>irb
    irb(main):001:0> require 'watir'
    LoadError: no such file to load -- watir
    from (irb):1:in `require'
    from (irb):1
    irb(main):002:0>

    ReplyDelete
  3. Sorry for the late reply. What's the issue?

    ReplyDelete