Here is the code for a very simple example (using an arbitrarily
chosen publicly available website):
require 'watir'
require 'test/unit'
class TC_FileDownload < Test::Unit::TestCase
def test_file_download
10.times do
b = Watir::IE.new
b.goto(('
http://www.wa.gov/esd/lmea/download/download.htm'))
b.link(:url, '
http://www.wa.gov/esd/lmea/download/
em9496zp.zip').click_no_wait
sleep 10#dialog doesn't appear instantly
prompt_message = "Do you want to open or save this file?"
window_title = "File Download"
save_dialog = WIN32OLE.new("AutoItX3.Control")
# I removed these two lines to strip down the code to the
# absolute bare minimum, they don't make any difference to the problem
# save_dialog.WinWaitActive(window_title, prompt_message, 25)
# save_dialog.ControlFocus(window_title, prompt_message, "&Open")
save_dialog.Send("O")
b.refresh
assert(b.contains_text('The Annual Labor Market and Economic
Report'))
b.close
end
end
end
Runs fine with the rdesktop session active (10 assertions, 0 failures,
0 errors). If I minimize the rdesktop window, the test errors and the
browser is hung on the download dialog.
1) Error:
test_file_download(TC_FileDownload):
WIN32OLERuntimeError: refresh2
OLE error code:80004005 in <Unknown>
<No Description>
HRESULT error code:0x80020009
Exception occurred.
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.4/./watir/ie.rb:381:in
`method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.4/./watir/ie.rb:381:in
`refresh'
Sandbox.rb:20:in `test_file_download'
Sandbox.rb:7:in `times'
Sandbox.rb:7:in `test_file_download'
1 tests, 0 assertions, 0 failures, 1 errors