Crazy.Coder --- have more fun in coding

世界上唯有两样东西能使我们的心灵受到深深的震撼,一是我们头顶上璀灿的星空,另一个便是人们内心深处的道德法则。 -- 康德

公告

统计

  • 随笔 - 42
  • 文章 - 0
  • 评论 - 62
  • 引用 - 0
handling popup window in Watir

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.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.

posted on 2007-04-17 18:44 CrazyCoder 阅读(...) 评论(...) 编辑 收藏