Handling popup window in testing browser based applications is always an annoying problem. watir provides a good solution for this, here is what I learned from the watir mail list and share it here to everyone else.
You will need newest watir (build late than 1.5.1.1079) to do it.
Here is the ruby scripts to handle popup windows:
# Des
Require 'watir' # The Controller
Require 'watir \ contrib \ enabled_popup'
Include watir
# Test: unit nodes des
Require 'test/unit'
Class tc_dimensionnet_login <test: Unit: testcase
Def test_window_popup
Testsite = "http: // localhost/test.htm"
$ Ie = watir: IE. New
$ Ie. Goto (testsite)
$ Ie. Button (: ID, "btnpopup"). Click
Startclicker ("OK", 5)
End
# Function click buttons on a popup window
Def startclicker (button, waittime = 9, user_input = nil)
Hwnd = $ ie. enabled_popup (waittime) # Get a handle if one exists
If (hwnd) # yes there is a popup
Puts hwnd
W = winclicker. New
If (user_input)
W. settextvalueforfilenamefield (hwnd, "# {user_input }")
End
Sleep 3 # I put this in to see the text being input it is not necessary to work
W. clickwindowsbutton_hwnd (hwnd, "# {button}") # "OK" or whatever the name on the button is
W = nil # This is just cleanup
End
End
End
Powered by scribefire.