我在用ruby的watir做web的自动化测试, 对于ie的弹出框处理写了一下的代码,使用了Thread.new加载处理
代码:require'rubygems'require'watir'require'test/unit'require'test/unit/ui/console/test...
代码:
require 'rubygems'
require 'watir'
require 'test/unit'
require 'test/unit/ui/console/testrunner'
require 'excelDSL'
require 'win32ole'
class Web_test < Test::Unit::TestCase
def check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
# Do forever - assumes popups could occur anywhere/anytime in your application.
loop do
# Look for window with given title. Give up after 1 second.
ret = autoit.WinWait('Microsoft Internet Explorer', '', 5)
# If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).
if (ret==1) then autoit.Send('{enter}') end
#if (ret==1) then
# autoit.ControlGetText("Microsoft Internet Explorer", "", "Static2")
#end
sleep(3)
end
end
def setup
@ie = Watir::IE.new
@ex = My_excel.new
@popup = Thread.new { check_for_popups } # start popup handler
end
def teardown
Thread.kill(@popup) # kill thread on exit of main application
end
def test_open
@ie.goto("http://www.XXXX.com")
@ie.text_field(:name, "email").set(@ex.exc_excel("D:\\b.xlsx")[0][0])
assert_equal("XXXXXXXXX", @ie.text_field(:name, "email").value, "faliure")
@ie.button(:id, "login-btn").click
end
end
运行后不能对弹出框自动关闭,请朋友们帮我解答,谢谢。 展开
require 'rubygems'
require 'watir'
require 'test/unit'
require 'test/unit/ui/console/testrunner'
require 'excelDSL'
require 'win32ole'
class Web_test < Test::Unit::TestCase
def check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
# Do forever - assumes popups could occur anywhere/anytime in your application.
loop do
# Look for window with given title. Give up after 1 second.
ret = autoit.WinWait('Microsoft Internet Explorer', '', 5)
# If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).
if (ret==1) then autoit.Send('{enter}') end
#if (ret==1) then
# autoit.ControlGetText("Microsoft Internet Explorer", "", "Static2")
#end
sleep(3)
end
end
def setup
@ie = Watir::IE.new
@ex = My_excel.new
@popup = Thread.new { check_for_popups } # start popup handler
end
def teardown
Thread.kill(@popup) # kill thread on exit of main application
end
def test_open
@ie.goto("http://www.XXXX.com")
@ie.text_field(:name, "email").set(@ex.exc_excel("D:\\b.xlsx")[0][0])
assert_equal("XXXXXXXXX", @ie.text_field(:name, "email").value, "faliure")
@ie.button(:id, "login-btn").click
end
end
运行后不能对弹出框自动关闭,请朋友们帮我解答,谢谢。 展开
3个回答
2012-02-27
展开全部
require 'watir\winClicker'
#require 'watir\contrib\enabled_popup'
ie = Watir::IE.new
ie.goto("http://mail.163.com/")
# 如果 IE 阻止了活动内容(JavaScript脚本)的运行,
# 需要利用这 5 秒时间手工点击IE信息栏,允许阻止的内容运行,
# 不然点击 Button 不会弹出窗口
sleep 5
ie.button(:id, 'loginBtn').click_no_wait
# 查找弹出窗口,设置查找超时时间为10秒
#如果窗口存在,则获取他的句柄,(10)指的是等待时间;
hwnd = ie.enabled_popup(10)
print hwnd
w = WinClicker.new
# 点击弹出窗口中的“确定”按钮
w.clickWindowsButton_hwnd(hwnd,"确定")
#require 'watir\contrib\enabled_popup'
ie = Watir::IE.new
ie.goto("http://mail.163.com/")
# 如果 IE 阻止了活动内容(JavaScript脚本)的运行,
# 需要利用这 5 秒时间手工点击IE信息栏,允许阻止的内容运行,
# 不然点击 Button 不会弹出窗口
sleep 5
ie.button(:id, 'loginBtn').click_no_wait
# 查找弹出窗口,设置查找超时时间为10秒
#如果窗口存在,则获取他的句柄,(10)指的是等待时间;
hwnd = ie.enabled_popup(10)
print hwnd
w = WinClicker.new
# 点击弹出窗口中的“确定”按钮
w.clickWindowsButton_hwnd(hwnd,"确定")
展开全部
试试蚂蚁浏览器, 它极少崩溃,能同时打开442个网页, 在百度搜蚂蚁浏览器 即可找到
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
发问www呜呜呜我呜呜呜呜呜呜我呜呜呜我我我呜呜呜我我呜呜呜我我呜呜呜我我呜呜呜我百度地图
本数据来源于百度地图,最终结果以百度地图最新数据为准。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询