views:

174

answers:

2

I am using Watir on Windows and when my script tries to run on Firefox, I see this error on my console:

JsshSocket::JSReferenceError:  Components is not definedReferenceError: Components is not defined
    C:/xampp/Ruby/lib/ruby/gems/1.8/gems/firewatir-1.6.5/lib/firewatir/jssh_socket.rb:12:in `js_eval'
    C:/xampp/Ruby/lib/ruby/gems/1.8/gems/firewatir-1.6.5/lib/firewatir/firefox.rb:195:in `goto'
    C:/xampp/Ruby/lib/ruby/gems/1.8/gems/firewatir-1.6.5/lib/firewatir/firefox.rb:164:in `start'
    C:/xampp/Ruby/lib/ruby/gems/1.8/gems/commonwatir-1.6.5/lib/watir/browser.rb:71:in `start'
    ./test.rb:12:in `test_prepare'

Does this happen to anyone else? What can I do to fix it?

+1  A: 

I haven't seen an error like this before. Here is the code that is failing.

  def js_eval(str)
    str.gsub!("\n", "")
    jssh_socket.send("#{str};\n", 0)
    value = read_socket()
    if md = /^(\w+)Error:(.*)$/.match(value)
      errclassname="JS#{md[1]}Error"
      unless JsshSocket.const_defined?(errclassname)
        JsshSocket.const_set(errclassname, Class.new(StandardError))
      end
      raise JsshSocket.const_get(errclassname), md[2]
    end
    value
  end

Your error is in this error-handling code, which to my eyes is overly complicated. If this error handling code were better, we'd have a better idea what is really causing your problem. Sorry I can't be of better help.

Bret Pettichord
Line 12 of jssh_socket.rb (from your stack trace) is the line above beginning with "raise"
Bret Pettichord
A: 

The "Components is not defined" message is a javascript error — it's coming back from the jssh_socket.send operation.

This discussion at support.mozilla.com describes the error as intermittent and harmless, which has been my experience too when using Watir + Firefox on Mac OS X (the JSReferenceError comes and goes, and doesn’t prevent the operations I’m trying to do).

So all I do is capture the exception, and ignore it:

browser = Watir::Browser.new
begin
  browser.goto 'http://www.thewebsiteiwant.com/'
rescue JsshSocket::JSReferenceError
  # do nothing
end

and let my Watir program continue.

Neil