0
    unknown property or method: `readyState'
        HRESULT error code:0x80010108
          The object invoked has disconnected from its clients. (NoMethodError)
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/browser.rb:603:in `method_missing'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/browser.rb:603:in `block in wait'
C:/Opt/Ruby/Ruby193/lib/ruby/1.9.1/timeout.rb:69:in `timeout'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/browser.rb:597:in `wait'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/container.rb:56:in `wait'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/container.rb:56:in `wait'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/element.rb:210:in `block in fire_event'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/element.rb:489:in `perform_action'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/element.rb:210:in `fire_event'
C:/Jenkins/workspace/UI_Automation_Dev/trunk/Automation/ocelot/lib/ocelot/extensions.rb:400:in `method_missing'

通过 Jenkins 在虚拟节点中执行时出现上述错误。当我在本地机器上手动运行时,没有错误。这是它抛出错误的块。

browser.frame(id: 'Iframe1').table(id: 'reviewHeader').td(id: 'RESAVE').when_present.click #clicking Save button
sleep(3) # Wait after Save so the 3rd party app. window closes
browser.window(title: /user/).use # Switch back to the main app window
browser.wait_for_page_load

在这里,我单击保存按钮,关闭选项卡。然后,我睡了 3 秒钟。然后,我使用标题为“用户”的窗口,并等待页面加载。单击“保存”按钮后出现错误;它不会切换到窗口。我什至尝试给予更多/更少的睡眠时间,但没有奏效。顺便说一句,我正在使用 Watir Classic。

4

1 回答 1

0

重现异常

查看异常发生的位置,我能够通过以下方式模拟异常:

1. 创建并打开一个带有 HTML 的窗口(这是主窗口):

<html>
  <head><title>user</title></head>
  <body><a href="popup.htm" target="_blank">popup</a></body>
</html>

2.创建并打开一个文件名为“popup.htm”和HTML的窗口(这是弹出窗口):

<html>
  <head><title>popup</title></head>
  <body><a href="#" id="RESAVE">Re-save</a></body>
</html>

3. 通过手动交互运行以下 Watir 脚本:

browser = Watir::Browser.attach(:url, /popup/)
Watir::Browser::READYSTATES = {complete: 5}
browser.link.click # while this is running, which is 300 seconds, manually close the popup
#=> `method_missing': unknown property or method: `readyState' (NoMethodError)
#=>    HRESULT error code:0x80010108
#=>      The object invoked has disconnected from its clients.

解决方案

异常发生在Browser#wait方法的这一部分,特别是@ie.readyState命令:

begin
  while @ie.busy
    sleep interval
  end

  until READYSTATES.has_value?(@ie.readyState)
    sleep interval
  end

  until @ie.document
    sleep interval
  end

  documents_to_wait_for = [@ie.document]
rescue WIN32OLERuntimeError # IE window must have been closed
  @down_load_time = ::Time.now - start_load_time
  return @down_load_time
end

编写代码是为了挽救关闭的窗口。但是,我不确定为什么它只包括WIN32OLERuntimeError我们获得NoMethodError. 考虑到这段代码的使用年限,底层的 WIN32OLE 可能随着时间的推移改变了它的返回类型,或者它可能只是另一个可能的异常。无论如何,猴子修补wait方法也可以处理NoMethodError将解决异常。

require 'watir-classic'
module Watir
  class Browser
    def wait(no_sleep=false)
      @xml_parser_doc = nil
      @down_load_time = 0.0
      interval = 0.05
      start_load_time = ::Time.now

      Timeout::timeout(5*60) do
        begin
          while @ie.busy
            sleep interval
          end

          until READYSTATES.has_value?(@ie.readyState)
            sleep interval
          end

          until @ie.document
            sleep interval
          end

          documents_to_wait_for = [@ie.document]
        rescue WIN32OLERuntimeError, NoMethodError # this is the only line modified
          # IE window must have been closed
          @down_load_time = ::Time.now - start_load_time
          return @down_load_time
        end

        while doc = documents_to_wait_for.shift
          begin
            until READYSTATES.has_key?(doc.readyState.to_sym)
              sleep interval
            end
            @url_list << doc.location.href unless @url_list.include?(doc.location.href)
            doc.frames.length.times do |n|
              begin
                documents_to_wait_for << doc.frames[n.to_s].document
              rescue WIN32OLERuntimeError, NoMethodError
              end
            end
          rescue WIN32OLERuntimeError
          end
        end
      end

      @down_load_time = ::Time.now - start_load_time
      run_error_checks
      sleep @pause_after_wait unless no_sleep
      @down_load_time
    end  
  end
end

如果问题只出现在单个脚本的这一步,最安全的解决方案可能就是在一个地方挽救异常:

begin
  browser.frame(id: 'Iframe1').table(id: 'reviewHeader').td(id: 'RESAVE').when_present.click #clicking Save button
rescue NoMethodError
  # window was likely closed
end
于 2017-01-22T03:48:53.887 回答