I've released a gem for a ruby library that I hope people will find useful,
and I believe will be of interest to those using watir. The library is
called WinWindow, and its aim is to represent a window (such as an IE
window, or a javascript popup), and expose windows API methods in an
object-oriented, ruby-like way.

The project's site is at http://winwindow.vapir.org/

It was borne of frustration with winClicker and AutoIt, and I wrote it to
replace, improve, and expand on functionality that watir currently uses
those libraries for. Namely, interaction with modal dialogs (getting text,
entering text, clicking buttons, closing); maximizing/focusing windows;
dealing with File Upload dialogs. It also does screen captures, which I
implemented because the win32screenshot gem was broken, although Jarmo has
since fixed that gem.

Some sample code showing use with watir, to close a javascript popup,
follows:

$ irb -r watir
>> require 'winwindow'
=> true
# launch a new browser
>> ie=Watir::IE.new
=> #<Watir::IE:0x36fece8 url="about:blank" title="">
# create a WinWindow representing the browser
>> w=WinWindow.new(ie.hwnd)
=> #<WinWindow:0x36e3688 @text="Blank Page - Windows Internet Explorer",
@hwnd=395016, @class_name="IEFrame">
# go to a site that'll give us a javascript popup
>> ie.goto "http://www.mediacollege.com/internet/javascript/basic/alert.html
"
=> 2.953125
# click the button to create the popup
>> ie.button(:value, /alert/).click_no_wait
=> ""
# see if the popup is on the window
>> w.enabled_popup
=> #<WinWindow:0x3642810 @text="Windows Internet Explorer", @hwnd=15076272,
@class_name="#32770">
# click the "OK" button on the popup. the 'try_for' part tells it how many
# seconds to try, because sending click messages through the windows API is
# not very reliable and just doing it once tends to fail.
>> w.enabled_popup.click_child_button_try_for!('OK', 4)
=> true
# popup is gone.

tl;dr version: to click on a button on ie's popup with text button_text
(trying for n seconds), you can use

WinWindow.new(ie.hwnd).enabled_popup.click_child_button_try_for!(button_text,
n)


I hope you'll give it a try and let me know what you think.

-Ethan
_______________________________________________
Wtr-development mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-development

Reply via email to