Testing Watir on Firefox throws JsshSocket::JSReferenceError

531 views Asked by At

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?

2

There are 2 answers

0
Neil On

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.

1
Bret Pettichord On

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.