watir web测试数据驱动实例

一 测试网址http://account1.51v.cn/ChargeThrough/ItemShop--0.html

二 业务逻辑分析,自动化测试框架架设

三 自动化测试数据文档搭建,如图

                   

四  编写执行代码

 require "watir"
require "watir/WindowHelper"
require "rubygems"
require "Win32API"
require "hpricot"
require "MouseClick"
require "win32ole"
excel = WIN32OLE.new("excel.Application")
workbook=excel.Workbooks.Open('C://Documents and Settings//Administrator//My Documents//ruby-web-testcase//buything.xls')
worksheet = workbook.Worksheets(1)
worksheet.Select
line=2
itemsnumber=[]
paytpye=[]
buytpye=[]
buynum=[]
givenmaninfoclass=[]
givenmaninfo=[]
while worksheet.Range("a#{line}")['value']
  puts worksheet.Range("a#{line}:b#{line}:c#{line}:d#{line}:e#{line}:f#{line}")['value']
  itemsnumber<<worksheet.Range("a#{line}")['value']
  paytpye<<worksheet.Range("b#{line}")['value']
  buytpye<<worksheet.Range("c#{line}")['value']
  buynum<<worksheet.Range("d#{line}")['value']
  givenmaninfoclass<<worksheet.Range("e#{line}")['value']
  givenmaninfo<<worksheet.Range("f#{line}")['value']
  line=line+1
end
i=0
ie= Watir::IE.new
while i<=itemsnumber.size-1
test_site="http://192.168.0.6/chthnew/"
ie.goto(test_site)
ie.bring_to_front
ie.image(:src,"http://192.168.0.6/chthnew/images/new/left_myitem.jpg").click
#检查购买道具初始信息
#检查购买道具初始信息
puts("Step 1:进入道具商城")
ie.image(:src,"http://static.51v.cn/ChargeWebNew/images/new/left_itemshop.jpg").click
puts("Step 2:选择中意商品")
ie.cell(:text,itemsnumber[i]).parent.parent.parent.fire_event("onmouseover")
puts("Step 3:购买商品")
ie.image(:src,"http://192.168.0.6/ChThNew/itemshop_images/buy_btn.gif").click
puts("Step 4:选择支付方式")
ie.radio(:id,paytpye[i]).click
#connet to sql database get the usermoney
#connet to sql database get the usermoney
puts("Step 5:选择购买用途")
ie.radio(:id,buytpye[i]).click
exituser=true
if(buytpye[i]=="BuyType_1")
  if(givenmaninfoclass[i]=="用户名")
    ie.radio(:id,"UserNameOrIDUC1_RadioButtonListNameInfo_0").click
#connect the database detem the userexit
#connect the database detem the userexit
    ie.text_field(:id,"UserNameOrIDUC1_TLName").set(givenmaninfo[i])
    else if(givenmaninfoclass[i]=="用户ID")
      ie.radio(:id,"UserNameOrIDUC1_RadioButtonListNameInfo_1").click
      ie.text_field(:id,"UserNameOrIDUC1_TLName").set(String(givenmaninfo[i]))
    end
#connect the database detem the userexit
#connect the database detem the userexit
  end
  ie.image(:src,"http://static.51v.cn/ChargeWebNew/images/jczh.gif").click
  outputtext=ie.div(:id,"DivUserChcek").text
#checkpoint if the outputtext is correct
#checkpoint if the outputtext is correct
end
puts("Step 6:购买数量")
buynumber=Integer(buynum[i])
puts(buynumber)
ie.text_field(:id,"TAmount").set(String(buynumber))
#compute the result money
#compute the result monet
puts("Step 7:确认购买")
ie.button(:id,"Button1").left_click
sleep 1
ie.button(:id,"Button1").transactdialog
if(!exituser)
#checkpoint span id=LabelInfo=请输入您要赠送的用户ID或用户名。
#checkpoint span id=LabelInfo=请输入您要赠送的用户ID或用户名。
exit
end
sleep 1
ie.cell(:id,"leftbar").transactdialog
#checkpoint connect the database and compute the real reult is correct
#checkpoint connect the database and  compute the real reult is correct
puts("trun completed")
ie.image(:src,"http://static.51v.cn/ChargeWebNew/images/new/left_mylist.jpg").click
#check the result
#check the result
#insert the test resule
#insert the test resule
i=i+1
end
excel.quit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值