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秒钟。然后,我使用标题为'user'的窗口,我等到页面加载。单击“保存”按钮后出现错误;它不会切换到窗口。我甚至尝试过更多/更少的睡眠时间,但它没有用。顺便说一下,我正在使用Watir Classic。
答案 0 :(得分: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