This block of code does not play nicely when User Account Control (UAC) is
turned on.

shell = WIN32OLE.new('Shell.Application')
shell.Windows.each do |window|
  ...
end

 When I turn off UAC, all Watir unit tests (except one) run correctly,
regardless of whether I am running as Administrator.




require 'rubygems'
require 'watir'
Watir::Browser.default = 'ie'

# Open a bunch of windows
[
  'http://www.ruby-lang.org/en/',
  'http://watir.com/',
  'http://google.com',
].each do |url| Watir::Browser.start(url) end

# Enumerate the windows. This is a stripped-down version of
# the loop that is eventually called by Watir::IE#attach.
#
# The expectation is that every one of the pages we just opened
# will show up in this list, each in a separate window.
#
# What actually happens depends at least on OS version, User Account Control
# settings, and whether the script is being run from an Administrator
# command prompt.
#
# OS = XP           all windows are enumerated
# OS = Vista        probably the same as Windows 7; untested (by me)
# OS = Windows 7
#    UAC off                         all windows are enumerated
#    UAC on, not running as Admin    all windows are enumerated
#    UAC on, running as Admin        only the first window is enumerated
#
Watir::IE.each do |ie|
  window = ie.ie
  puts "#{window.locationURL}  #{window.locationName}"
end
puts

# Watir::IE.each is looking for 'Internet Explorer' as part of the
# window path, so let's enumerate those.
#
puts '----------------'
shell = WIN32OLE.new('Shell.Application')
shellWindows = shell.Windows
puts "window count = #{shellWindows.count}"
shell.Windows.each do |window|
  puts "#{window.hwnd}  #{window.path}" rescue false
end
puts
_______________________________________________
Wtr-development mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-development

Reply via email to