关闭

数据驱动在QTP中的运用(四) - 使用SQL数据库

标签: sql数据库dialogloginsecurityclass
1190人阅读 评论(0) 收藏 举报
分类:

本篇主要讲述Flight打开订单的正确性测试,通过数据库进行数据驱动测试,主要步骤和考虑思路如下:

1.从数据库中随机读取一条存在的记录
2.在Flight中打开本条记录
3.比较数据库中的数据和软件界面上的显示是否一致
   - 其中数据库中读出的记录数据保存在局部变量中
   - 界面显示的实际数据通过Output Value保存到QTP自带的DataTable中.

 

Option Explicit

Dim conn, rst, maxnumber, rndNumber, sql
Dim dbFlightNumber, dbTicketNumber, dbPlaneType, dbCustomerName
Dim oPlaneType
'------------------------------------------------------------------------------------------------------------------------------------------------------

'获取数据库中的记录数据(期望结果)
Const  strConn = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=QT_Flight32"
Set conn=CreateObject("Adodb.Connection")
Set rst=CreateObject("Adodb.RecordSet")
conn.open strConn

'获取最大Order_Number
sql = "select max(order_number) from orders "
rst.Open sql, conn
maxNumber = rst.Fields(0).Value
rst.Close

'随即获取一条记录
rndNumber = RandomNumber(1, maxNumber)
sql = "Select  Flight_Number, Tickets_Ordered, Class, Customer_Name  from orders where order_number =" & CStr(rndNumber)
rst.Open sql, conn

While rst.EOF
 rndNumber = RandomNumber(1, maxNumber)
 sql = "Select  Flight_Number, Tickets_Ordered, Class, Customer_Name  from orders where order_number =" & CStr(rndNumber)
 rst.Open sql, conn
Wend

rst.MoveFirst
While not rst.EOF
    dbFlightNumber = rst.Fields(0).value
    dbTicketNumber =rst.Fields(1).value
    dbPlaneType = rst.Fields(2).value
    dbCustomerName = rst.Fields(3).value
    rst.MoveNext
Wend

conn.close
Set rst=nothing
Set conn=nothing


'------------------------------------------------------------------------------------------------------------------------------------------------------
'录制脚本程序
SystemUtil.CloseProcessByName "Flight4a.exe"
SystemUtil.Run Environment.Value("ProductDir") & "/samples/flight/app/flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set "Admin"
Dialog("Login").WinEdit("Password:").Set "Mercury"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set rndNumber  '在这里Set 随机打开的订单
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Window("Flight Reservation").Activate


'获取 界面显示的实际数据(实际结果)
Window("Flight Reservation").WinEdit("Flight No:").Output CheckPoint("Flight No:")
Window("Flight Reservation").WinEdit("Tickets:").Output CheckPoint("Tickets:")
Window("Flight Reservation").WinEdit("Name:").Output CheckPoint("CustomerName")

'将界面上的仓位转换为1,2,3
If Window("Flight Reservation").WinRadioButton("First").GetROProperty("Text") = "ON" Then
 oPlaneType = 1
ElseIf Window("Flight Reservation").WinRadioButton("Business").GetROProperty("Text") = "ON" Then
 oPlaneType = 2
ElseIf Window("Flight Reservation").WinRadioButton("Economy").GetROProperty("Text") = "ON" Then 
 oPlaneType = 3
End If


'检查Flight Number
If CStr(dbFlightNumber) = CStr(DataTable("oFlightNumber", dtLocalSheet)) Then
 Reporter.ReportEvent micPass, "打开订单- Flight Number", "期望结果是:" & dbFlightNumber & ", 界面显示实际结果是:" & DataTable("oFlightNumber", dtLocalSheet)
Else
 Reporter.ReportEvent micPass, "打开订单- Flight Number", "期望结果是:" & dbFlightNumber & ", 界面显示实际结果是:" & DataTable("oFlightNumber", dtLocalSheet)
End If

'检查Ticket Number
If CStr(dbTicketNumber) = CStr(DataTable("oTicketNumber", dtLocalSheet)) Then
 Reporter.ReportEvent micPass, "打开订单- TicketNumber", "期望结果是:" & dbTicketNumber & ", 界面显示实际结果是:" & DataTable("oTicketNumber", dtLocalSheet)
Else
 Reporter.ReportEvent micPass, "打开订单- TicketNumber", "期望结果是:" & dbTicketNumber & ", 界面显示实际结果是:" & DataTable("oTicketNumber", dtLocalSheet)
End If

'检查Customer Name
If CStr(dbCustomerName) = CStr(DataTable("oCustomerName", dtLocalSheet)) Then
 Reporter.ReportEvent micPass, "打开订单- CustomerName", "期望结果是:" & dbCustomerName & ", 界面显示实际结果是:" & DataTable("oCustomerName", dtLocalSheet)
Else
 Reporter.ReportEvent micPass, "打开订单- CustomerName", "期望结果是:" & dbCustomerName & ", 界面显示实际结果是:" & DataTable("oCustomerName", dtLocalSheet)
End If

'检查Plane Type
If CStr(dbPlaneType) = CStr(oPlaneType) Then
 Reporter.ReportEvent micPass, "打开订单- Plane Type", "期望结果是:" & dbPlaneType & ", 界面显示实际结果是:" & oPlaneType
Else
 Reporter.ReportEvent micPass, "打开订单- Plane Type", "期望结果是:" & dbPlaneType & ", 界面显示实际结果是:" & oPlaneType
End If

'Close Prog
Window("Flight Reservation").Close

 


 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:87808次
    • 积分:1414
    • 等级:
    • 排名:千里之外
    • 原创:48篇
    • 转载:29篇
    • 译文:0篇
    • 评论:37条