Watir Popup 采用新线程进行处理

require 'watir'
 require 'win32ole'
$h"A I o T9~o#n*X*~0def check_for_popups(title="Microsoft Internet Explorer", button="OK")51Testing软件测试网0T o A-F e w8q ?
    popup=Thread.new{
&g7U(j9J,W y0        autoit=WIN32OLE.new('AutoItX3.Control')51Testing软件测试网(d q"k1o;^)p8R
        ret=autoit.WinWait(title,"",60)
qt.`$o R.o x p D v0       if(ret==1)
u C5d,\6~,r"|$j0            puts"There is popup."
3t u L.U Q I.[5l B q0            autoit.WinActivate(title)51Testing软件测试网 w T4x J j t ? v
            button.downcase!51Testing软件测试网 j y l t Y _ g+O
           ifbutton.eql?("ok") || button.eql?("yes") || button.eql?("continue")
K%K f%D-| \ } L:V!}6J R0                autoit.Send("{Enter}")51Testing软件测试网 U2`7Z i F@
           else51Testing软件测试网 [ Y k z J'i @ D%P
                autoit.Send("{tab}")
5j X9m y l L2U T0                autoit.Send("{Enter}")51Testing软件测试网 p)~8N5t6l&m5@
            end
;J+H x+R S$j"g:\G0        elsif (ret==0)
(Q H d/F)N \/J9Z Q I J P0            puts"No popup, please check your code."
Q w%F S+Q K)j0        end
(h d!m N C0    }
)W9| V } J1h k6f0    at_exit {Thread.kill(popup) }
7o j So!G0end51Testing软件测试网3i ~ n E)P
51Testing软件测试网 C N!D/z.V l'i,O
$ie.link(:text,//).click_no_wait51Testing软件测试网.s V+V [ j.a k y ] g:z
check_for_popups("MicrosoftInternet Explorer","OK")51Testing软件测试网"e u3W O F9Y5X/H }
这个方法针对 Popup是 OK/cancel之类的弹出框比较有效。

posted on 2011-04-15 15:41  张飞_  阅读(312)  评论(0编辑  收藏  举报

导航