一天一个关于测试知识点,5分钟内讲解你最关心的软件测试问题,今天就接着来谈谈关于软件测试中的“自动化测试实例三: 脚本开发(下)”
一、调用测试用例,判断测试结果。
仅仅通过上面对脚本增强还不够,不能做到真正的自动化测试,还必须让脚本正确地执行所有用例,并且同时判断每个测试用例执行的结果。
对于登录功能调用测试用例后的脚本如下:
Dim errInfo '返回提示的错误信息
For i=3 to GetExcleSheetRowsCount("C:\testcase","Login")
BusinessName = GetExcelCells(ReadExcelPath,"Login",i,3)
TestCaseID = GetExcelCells(ReadExcelPath,"Login",i,2)
ReadString = GetExcelCells("C:\testcase","Login",i,6)
arrExcelLines = split(ReadString,",")
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","",""
Dialog("Login").WinEdit("Agent Name:").Set arrExcelLines(0)
Dialog("Login").WinEdit("Password:").SetSecure arrExcelLines(1)
Dialog("Login").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist Then
errInfo = Dialog("text:=Login").Dialog("text:=Flight Reservations").Static("window
id:=65535").GetROProperty("text")
If errInfo = GetExcelCells("C:\testcase","Login",i,7) Then
WriteHtml BusinessName,TestCaseID,"PASS",date,errInfo,GetExcelCells("C:\testcase", "Login",i,7)
else
WriteHtml BusinessName,TestCaseID,"FAIL",date,errInfo,GetExcelCells("C:\testcase", "Login",i,7)
End If
Dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click
Dialog("Login").Close
else
wait(5)
WriteHtml BusinessName,TestCaseID,"PASS",date,"登录成功",GetExcelCells("C:\testcase", "login",i,7)
Window("Flight Reservation").Close
End If
Next
订票流程功能脚本不但需要调用测试用例,并且在选择出发城市和到达城市时需要随机选择,选择好出发城市和到达城市后,在选择航班时也需要做到随机选择,这样能更好地模拟真实的情况。
订票完成后需要检查订票信息是否已经写入数据库,即需要检查 Orders 表中是否添加了相关的订单信息,增强后的脚本如下:
Dim errInfo '返回提示的错误信息
Dim flightcount '航班总数
Dim ordersinfo '订单号
Dim flag '标识订单是否在数据库中存在
flag = 0
For i=3 to GetExcleSheetRowsCount("C:\testcase","Tickets")
BusinessName = GetExcelCells(ReadExcelPath,"Tickets",i,3)
TestCaseID = GetExcelCells(ReadExcelPath,"Tickets",i,2)
ReadString = GetExcelCells("C:\testcase","Tickets",i,6)
arrExcelLines = Split(ReadString,",")
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","",""
Call Login()
wait(5)
Window("Flight Reservation").ActiveX("MaskEdBox").Type arrExcelLines(0)
'随机选择出发城市
Randomize
randno = Int((9 * Rnd))
Window("Flight Reservation").WinComboBox("Fly From:").Select randno
If Window("Flight Reservation").Dialog("Flight Reservations").Exist Then
errInfo = Window("regexpwndtitle:=Flight Reservation").Dialog("text:=Flight Reservations"). Static("window
id:=65535").GetROProperty("text")
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("确定").Click
If errInfo = GetExcelCells("C:\testcase","Tickets",i,7) Then
WriteHtml BusinessName,TestCaseID,"PASS",date,errInfo,GetExcelCells("C:\testcase", "Tickets",i,7)
else
WriteHtml BusinessName,TestCaseID,"FAIL",date,errInfo,GetExcelCells("C:\testcase", "Tickets",i,7)
End If
else
'随机选择到达城市
Randomize
randno = Int((9 * Rnd))
Window("Flight Reservation").WinComboBox("Fly To:").Select randno
Window("Flight Reservation").WinButton("FLIGHT").Click
flightcount = Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCount
'随机选择航班
Randomize
randflight = Int(((flightcount-1)* Rnd))
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select randflight
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set arrExcelLines(1)
Window("Flight Reservation").WinButton("Insert Order").Click
wait(10)
ordersinfo = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
wait(5)
call ConnectDatabase
Rst.Open "select * from orders",Conn
Do While Not Rst.EOF
strDb=Rst.Fields.item(0)
If strDb=info Then
flag = flag + 1
WriteHtml BusinessName,TestCaseID,"PASS",date,"订票成功",GetExcelCells ("C:\testcase","Tickets",i,7)
End If
Rst.MoveNext
Loop
End If
If flag=1 Then
WriteHtml BusinessName,TestCaseID,"PASS",date,"订票成功",GetExcelCells("C:\testcase", "Tickets",i,7)
else
WriteHtml BusinessName,TestCaseID,"FAIL",date,"订票失败",GetExcelCells("C:\testcase", "Tickets",i,7)
End If
Window("Flight Reservation").Close
Next
航班信息功能不需要读取数据,但需要随机选择出发城市和到达城市,当输入出发城市和到达城市后,应该检查弹出的航班信息对话框中的所有航班信息是否成功,即是否与 Flights 表中的记录对应,增强后的脚本如下:
Dim flightinfo '显示所有航班信息
Dim flightcount '一共有多少次航班
Dim falg
For i=0 to 5
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","",""
Call Login()
wait(5)
Window("Flight Reservation").ActiveX("MaskEdBox").Type "121212"
Randomize
randnoDeparturecity = Int((9 * Rnd))
Window("Flight Reservation").WinComboBox("Fly From:").Select randnoDeparturecity
Departurecity = Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")
'当选择了出发城市后,到达城市就只有 9 个,这样只要随机到 0~8 即可
Randomize
randnoArrivalcity = Int((8 * Rnd))
Window("Flight Reservation").WinComboBox("Fly To:").Select randnoArrivalcity
Arrivalcity = Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("text")
Window("Flight Reservation").WinButton("Flight").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Click
flightinfo = Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetROProperty ("all items")
flightcount = Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCount
Call ConnectDatabas()
Conn.Open StrConn
sql = "select * from flights where Departure='"+Departurecity+"' and Arrival='"+Arrivalcity+"' and Day_Of_Week=
'Wednesday'"
Rst.Open sql,Conn
Do While Not Rst.EOF
strDb=Rst.Fields.item(0)
Pos = Instr(1, flightinfo, strDb, 1)
msgbox Pos
If Pos >0 Then
falg = falg + 1
End If
Rst.MoveNext
Loop
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
If falg = flightcount Then
WriteHtml BusinessName,TestCaseID,"PASS",date,"航班信息正确",GetExcelCells
("C:\testcase","Airline",i,7)
else
WriteHtml BusinessName,TestCaseID,"FAIL",date,"航班信息错误",GetExcelCells
("C:\testcase","Airline",i,7)
End If
Window("Flight Reservation").Close
Next
查询订票信息功能增强,即随机输入一个订单号,当该订单号存在时,需要进一步判断相关的信息是否正确,如果正确,说明该测试通过,否则测试失败。增强后的脚本如下:
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","",""
Call Login()
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Randomize
orderno = Int((100 * Rnd)+1)
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set orderno
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Exist Then
errInfo = Window("regexpwndtitle:=Flight Reservation").Dialog("text:=Open Order").Dialog
("regexpwndtitle:=Flight Reservations").Static("window id:=65535").GetROProperty("text")
If errInfo=GetExcelCells("C:\testcase","Query",i,7) Then
WriteHtml BusinessName,TestCaseID,"PASS",date,errInfo,GetExcelCells("C:\testcase","Query",i,7)
else
WriteHtml BusinessName,TestCaseID,"FAIL",date,errInfo,GetExcelCells("C:\testcase","Query",i,7)
End If
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("确定").Click
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Close
End If
Call ConnectDatabase()
sql="select * from orders where Order_Number ='"+orderno+"'"
Rst.Open sql,Conn
Do While Not Rst.EOF
strDb=Rst.Fields.item(0)
Window("Flight Reservation").Static("Order No:").GetROProperty("text")
If Rst.Fields.item(0)=Window("Flight Reservation").Static("Order No:").GetROProperty("text") and Rst.Fields.item(1)=
Window("Flight Reservation").Static("Name:").GetROProperty("text") and Rst.Fields. item(3)=Window("Flight Reservation").
Static("Flight No::").GetROProperty("text")Then
WriteHtml BusinessName,TestCaseID,"PASS",date,errInfo,GetExcelCells("C:\testcase","Query",i,7)
Else
WriteHtml BusinessName,TestCaseID,"FAIL",date,errInfo,GetExcelCells("C:\testcase","Query",i,7)
End If
Rst.MoveNext
Loop
Window("Flight Reservation").Close
二、执行测试
脚本开发完成后,即可开始执行脚本,这些脚本主要是功能方面的验证测试。功能验证测试也可以理解为每日构建测试,主要是对系统每日新增或修改的代码进行测试,以保证新增或修改的代码不会对关键功能产生影响。
三、提交测试报告
在执行脚本过程中,需要记录每一轮测试用例执行的情况,即测试用例记录,当整个项目的自动化测试完成后,需要提交相关的测试报告。
[自动化测试小结]
本章主要介绍了自动化测试相关的知识,自动化测试的目的、范围,测试的程度和测试对象;自动化测试的优缺点和当前自动化测试普遍存在的问题;当前主流的自动化测试工具、自动化测试框架和自动化测试的过程。通过本章的学习,重点了解什么是自动化测试、自动化测试框架和自动化测试过程。最后通过介绍一个自动化测试实例,使读者更好地学习自动化测试的相关知识,但要进一步了解自动化测试,还必须阅读相关的自动化测试资料。
今天关于“自动化测试实例三: 脚本开发(下)”就学习到这里了,每个工作日小编都会更新一个小知识,希望大家多多关注我们,一起来学习喔!