























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:
#includes
require 'watir' # the controller
require 'watir\contrib\enabled_popup'
include Watir#test::unit includes
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.newif ( user_input )
w.setTextValueForFileNameField( hwnd, "#{user_input}" )
endsleep 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 cleanupend
end
end
Powered by ScribeFire.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。