lib/watir/ie-class.rb in watir-1.7.0.rc1 vs lib/watir/ie-class.rb in watir-1.7.0

- old
+ new

@@ -231,18 +231,22 @@ end # Yields successively to each IE window on the current desktop. Takes a block. # This method will not work when # Watir/Ruby is run under a service (instead of a user). - # Yields to the window and its hwnd. + # Yields to the window and its hwnd. def self.each shell = WIN32OLE.new('Shell.Application') + ie_browsers = [] shell.Windows.each do |window| next unless (window.path =~ /Internet Explorer/ rescue false) next unless (hwnd = window.hwnd rescue false) ie = IE.bind(window) ie.hwnd = hwnd + ie_browsers << ie + end + ie_browsers.each do |ie| yield ie end end # return internet explorer instance as specified. if none is found, @@ -310,11 +314,11 @@ attr_writer :hwnd # Are we attached to an open browser? def exists? begin - @ie.name =~ /Internet Explorer/ + !!(@ie.name =~ /Internet Explorer/) rescue WIN32OLERuntimeError false end end alias :exist? :exists? @@ -396,10 +400,16 @@ return unless exists? @ie.stop wait rescue nil chwnd = @ie.hwnd.to_i @ie.quit - while Win32API.new("user32","IsWindow", 'L', 'L').Call(chwnd) == 1 + t = Time.now + while exists? + # just in case to avoid possible endless loop + if Time.now - t > 10 + puts "Impossible to close all IE windows, continuing." + break + end sleep 0.3 end end # Maximize the window (expands to fill the screen)