在 Firefox 上测试 Watir 会抛出 JsshSocket::JSReferenceError

发布于 2024-08-27 19:32:37 字数 643 浏览 11 评论 0原文

我在 Windows 上使用 Watir,当我的脚本尝试在 Firefox 上运行时,我在控制台上看到此错误:

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'

其他人也会发生这种情况吗?我可以做什么来修复它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬色的秋千 2024-09-03 19:32:37

我以前没有见过这样的错误。这是失败的代码。

  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

您的错误在于此错误处理代码中,在我看来,该代码过于复杂。如果这个错误处理代码更好,我们就能更好地了解真正导致问题的原因。抱歉,我无法提供更好的帮助。

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.

蘸点软妹酱 2024-09-03 19:32:37

“组件未定义”消息是一个 JavaScript 错误 - 它是从 jssh_socket.send 操作返回的。

support.mozilla.com 上的讨论 将错误描述为间歇性且无害的,这也是我在 Mac OS X 上使用 Watir + Firefox 时的经验(JSReferenceError 来来去去,并且不会阻止我尝试执行的操作)。

所以我所做的就是捕获异常,然后忽略它:

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

让我的 Watir 程序继续。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文