一 测试网址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