51Testing软件测试论坛

标题: 小弟跪求一段特别特别专业的QTP脚本代码 [打印本页]

作者: zhangkun90    时间: 2013-1-25 09:46
标题: 小弟跪求一段特别特别专业的QTP脚本代码
哎 才了解QTP不久,可是现在感觉到迷茫了 不知道 专业的QTP代码书写是啥样的, 我也想知道我看看能不能看懂 非常专业的QTP脚本代码, 所以在这里我想要一段专业点的QTP脚本代码 来读读 看看自己是不是也能写出这样的代码来
作者: davy_chen    时间: 2013-1-25 10:10
'========================================================================================
'  Test Name :         Open Order                                                                                                                                                                                                       
'
'  Description :  This test verifies that an order can be opened through the Open Order Form window by:
'                                1. The Order No.
'                                 2. The Date of Flight
'                                3. The Name of Customer
'
'  IMPORTANT NOTE!!! : The flight that is to be opened has to be unique to the database.  Therefore, the test uses an array variable
'                                                that can be changed by the tester, which holds all the neccessary information on the flight.
'
'   Note  :  The test will insert the order using insert_order() (flt_lib) and will delete the order when finished.  If the order is not successfully
'                        inserted into the database, the test will terminate.
'
'  Date   :  May 5,2004
'========================================================================================


'=========================== Static Variables and Functions ===========================================================
'Dictionary object to hold flight information for insertion. Like the use of Enum
Dim  flight
Set flight = CreateObject("Scripting.Dictionary")
flight.Add "Fly From", "Los Angeles"   ' Add some keys and items.
flight.Add "Fly To", "Denver"
flight.Add "Date", "060636"   '         meaning 06/06/2036
flight.Add "Flight No.", "1"
flight.Add "Class", "First"
flight.Add "Name", "Kenny Rogers"
flight.Add "Tickets","4"

'ItemDemo = d.Item("c")   ' Get the item.

'=================================================================================================================
RunAction "OpenApplication [FlightLib]", oneIteration
RunAction "InsertOrder [FlightLib]", oneIteration, flight("Name") , flight("Fly From"), flight("Fly To"), flight("Date"), flight("Flight No."), flight("Class"), flight("Tickets"), OrderNum
' Updated before the step
RunAction "ClearMainWindow [FlightLib1]", oneIteration

' STEP 1. Opening an order by the Order Number.
RunAction "OpenOrder [FlightLib1]", oneIteration,OrderNum
RunAction "ClearMainWindow [FlightLib1]", oneIteration

' STEP 2.  Opening an order by Date of Flight.
RunAction "OpenOrderForm [FlightLib]", oneIteration
Window("Flight Reservation").Dialog("Open Order").Activate
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinObject("FlightDateEdit").Type flight("Date")
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

'# Checking if application could open order using Date
If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Exist(2) Then
        Reporter.ReportEvent FAIL,"FlightDate: " , " Does not exist in the Database."
        Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
        Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
Else
        Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click
        Reporter.ReportEvent PASS,"FlightDate: " , " Flight Existed in the DB and opened successfully"
End If
RunAction "ClearMainWindow [FlightLib1]", oneIteration

' STEP 3.  Insert an order by Customer Name.
RunAction "OpenOrderForm [FlightLib]", oneIteration
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("CustomerNameEdit").Set  flight("Name")
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

'# Checking if application could open order using Date
If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Exist(2) Then
        Reporter.ReportEvent FAIL,"Name: " , " Such name doesn't exist in the DB."
        Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
        Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
Else
        Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click
        Reporter.ReportEvent PASS,"FlightDate: " , " Flight Existed in the DB and opened successfully"
End If
RunAction "ClearMainWindow [FlightLib1]", oneIteration

'put the order number
RunAction "DeleteOrder [FlightLib]", oneIteration,OrderNum
'clear window
RunAction "ClearMainWindow [FlightLib1]", oneIteration
作者: zhangkun90    时间: 2013-1-25 10:43
回复 2# davy_chen


    谢谢咯  先读读  我想知道更多的 比如 function 调用来  DOM  ADO 啥的   哎现在不知道啥时候用这些东西
作者: xjwldlover    时间: 2013-1-25 11:54
呵呵 别读了~,读不懂
高水平的代码不会是一小段,是数据组织、函数分解、信息共享的综合体,这样的代码一出来就是一大堆,你不先写垃圾的代码,就很难体会出好代码的好处。随便贴出一段你看不懂的代码,这未必是好代码。
作者: zhangkun90    时间: 2013-1-31 13:18
回复 4# xjwldlover


    哎 现在迷茫了 现在做的项目我们也在用QTP  哎 用到的无非是 取出对象空间的属性 判断属性是否正确  循环验证前台页面的JS校验, 没有用到什么 function、ado、也没框架 所以哎 现在我感觉缺少的是一种模板 。。嘿嘿




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2