zhangkun90 发表于 2013-1-25 09:46:07

小弟跪求一段特别特别专业的QTP脚本代码

哎 才了解QTP不久,可是现在感觉到迷茫了 不知道 专业的QTP代码书写是啥样的, 我也想知道我看看能不能看懂 非常专业的QTP脚本代码, 所以在这里我想要一段专业点的QTP脚本代码 来读读 看看自己是不是也能写出这样的代码来

davy_chen 发表于 2013-1-25 10:10:41

'========================================================================================
'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
Dimflight
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 ", oneIteration
RunAction "InsertOrder ", 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 ", oneIteration

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

' STEP 2.Opening an order by Date of Flight.
RunAction "OpenOrderForm ", 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 ", oneIteration

' STEP 3.Insert an order by Customer Name.
RunAction "OpenOrderForm ", oneIteration
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("CustomerNameEdit").Setflight("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 ", oneIteration

'put the order number
RunAction "DeleteOrder ", oneIteration,OrderNum
'clear window
RunAction "ClearMainWindow ", oneIteration

zhangkun90 发表于 2013-1-25 10:43:20

回复 2# davy_chen


    谢谢咯先读读我想知道更多的 比如 function 调用来DOMADO 啥的   哎现在不知道啥时候用这些东西

xjwldlover 发表于 2013-1-25 11:54:29

呵呵 别读了~,读不懂
高水平的代码不会是一小段,是数据组织、函数分解、信息共享的综合体,这样的代码一出来就是一大堆,你不先写垃圾的代码,就很难体会出好代码的好处。随便贴出一段你看不懂的代码,这未必是好代码。

zhangkun90 发表于 2013-1-31 13:18:32

回复 4# xjwldlover


    哎 现在迷茫了 现在做的项目我们也在用QTP哎 用到的无非是 取出对象空间的属性 判断属性是否正确循环验证前台页面的JS校验, 没有用到什么 function、ado、也没框架 所以哎 现在我感觉缺少的是一种模板 。。嘿嘿
页: [1]
查看完整版本: 小弟跪求一段特别特别专业的QTP脚本代码