继续连载...
首先查看帮助文档,查看set方法:
Description Sets the value ofthe edit box. //给文本框赋值 Syntax object.Set Text 示例: Sub Set_Example() 'The followingexample uses the Set method to set the file name 'document.txt inthe File name: edit box. Dialog("Open").WinEdit("File&name:").Set "document.txt" End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End SubSub Set_Example()
'The following example uses the Set method toset the file name
'document.txt in the File name: edit box.
Dialog("Open").WinEdit("File &name:").Set "document.txt"
End 编写增加订单脚本: Dialog("Login").WinEdit("Agent Name:").Set "test"
Dialog("Login").WinEdit("Password:").Set "Mercury"
Dialog("Login").WinButton("OK").Click
wait(2)
Window("FlightReservation").WinObject("Date of Flight:").Type "101116"
Window("FlightReservation").WinComboBox("Fly From:").Select 1
Window("FlightReservation").WinComboBox("Fly To:").Select 2
wait(2)
Window("FlightReservation").WinButton("FLIGHT").Click
Window("FlightReservation").Dialog("Flights Table").WinList("From").Select 1
Window("FlightReservation").Dialog("FlightsTable").WinButton("OK").Click
wait(1)
Window("FlightReservation").WinEdit("Name:").Set "tian"
Window("FlightReservation").WinButton("Insert Order").Click
注:脚本详解 点击”ok”之后,跳转到订单界面,页面出现需要时间,脚本中加入wait方法,wait之后的脚本便会延迟执行;Select是选取值,选第一个值,则用0,选二个,则用1,以此类推;直接点击按钮用click;为文本框赋值用set;Type方法是按照字符逐个输入,而set是一次性赋值。 执行完之后”OrderNo”产生
(3)检查FlyFrom与FlyTo下拉列表值。 功能分析:以FlyFrom为例,通过帮助文档,我们得知用GetItemsCount方法计算下拉框元素总个数,通过For循环获取其中某个值,然后与预期值进行比对。 脚本如下: flyFrom=Array("Denver","Frankfurt","London","LosAngeles","Paris","Portland","SanFrancisco","Seattle","Sydney","Zurich")
For i =0 to Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount-1
If (Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i)=flyFrom(i)) Then
msgbox i &" right"
Else
msgbox i & "wrong"
End If
Next 脚本分析: 把预期值存放于数组中,用GetItemsCount方法获取总数,用GetItem获取FlyFrom列表实际值,由于是从第一个值对应Item是0,故For语句总数要减1,数组Item也是从零开始,取”Denver”用flyFrom(0),取数组长度可用ubound方法,如:ubound(flyFrom),msgbox 是以弹出框的形式输出消息,vbs连接字符串需要用&符号
(4) 从工具栏新增订单 以 File->Open Order为例 首先需要把menu对象增加到对象库中,有以下两种方法可打开Open Order… 方法一: Window("FlightReservation").WinMenu("Menu").Select "File;OpenOrder..."
方法二:Window("FlightReservation").WinMenu("Menu").Select "<Item1>;<Item 2>" (5)对象库基本操作 对象库就是储存QTP各Object以及其识别属性,从而在被测应用程序中找到对应的唯一的对象
在进行写脚本之前,需要先增加对象库Resources->Object Repository,用鼠标点击Help下方”+”鼠标会变成”手”状,然后点击被测程序的UI元素,如点击Fly From,便会加入到对象库中.合并对象库: 如A同学在对象框中增加了FlyFrom,B同学在对象框中增加了FlyTo,我们可以把A,B同学的对象框合并成一个新的对象库包含FlyFrom与FlyTo 打开:Object->Object RepositoryManager->Tools->Object Repository Merge Tool
选择文件并”ok”,通过file-save便可得到合并后的对象库
|