51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1956|回复: 4
打印 上一主题 下一主题

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

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2013-1-25 09:46:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
哎 才了解QTP不久,可是现在感觉到迷茫了 不知道 专业的QTP代码书写是啥样的, 我也想知道我看看能不能看懂 非常专业的QTP脚本代码, 所以在这里我想要一段专业点的QTP脚本代码 来读读 看看自己是不是也能写出这样的代码来
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 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
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
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2013-1-25 10:43:20 | 只看该作者
回复 2# davy_chen


    谢谢咯  先读读  我想知道更多的 比如 function 调用来  DOM  ADO 啥的   哎现在不知道啥时候用这些东西
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2013-1-25 11:54:29 | 只看该作者
呵呵 别读了~,读不懂
高水平的代码不会是一小段,是数据组织、函数分解、信息共享的综合体,这样的代码一出来就是一大堆,你不先写垃圾的代码,就很难体会出好代码的好处。随便贴出一段你看不懂的代码,这未必是好代码。
回复 支持 反对

使用道具 举报

该用户从未签到

5#
 楼主| 发表于 2013-1-31 13:18:32 | 只看该作者
回复 4# xjwldlover


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

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-28 13:56 , Processed in 0.071902 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表