QTP - 10. DP (Descriptive Programming) 描述性编程
对象识别原理:Interaction with runtime objects NOT OR(object Repository); Uniquely indentify properties;
Not Good use: x, y, abs_x etc
Better use: title, regexpwndtitle etc
使用范围:Objectnot available; Object are dynamic; OR is too large; Modification on OR requiredbut affect others scripts; take action on large number of similar object.
注意:1.Once object use DP, its rest statement Must use DP as well. If page use DP,then WebButton must use DP.
2.If there are multiple objectmatches the DP, use ordinal identifiers. For example: Browser(“micclass:=Browser”,”index:=1”)
主题1:
TWO kinds DP:
Using description objects
Dim obj
Set obj = Description.Create
‘If you want to search all object, you need NOT adddescription identifies as following box:
Obj(“micclass”).value = link Obj(“text”).Value = “Search” |
Browser(“Google”).Page(“Google”).WebButton(obj).Click
‘或者遍历:
Set allChilds =Browser(“Google”).Page(“Google”).WebButton(obj)
For i = 0 To allChilds.Count – 1
allChilds.item(i).highlight
Next
1. Indirect way
set EditDesc = Description.Create()
EditDesc("Name").Value = "userName"
EditDesc("Index").Value = "0"
Browser("Welcome: Mercury").Page("Welcome: Mercury").Link(EditDesc).Click
Note: The default regular expression property for Description = true. If the property value no need property, pls set it = false.
EditDesc ("PropName").RegularExpression = False
EditDesc ("PropName").Value= "asd(12)" 'Note ( ) is mark for regular expressionUsing Description Strings
Set sButton = Browser(“Google”).Page(“Google”).WebButton(“name:=Google Search”,“type:=submit”, "index:=0")
sButton .Click
主题2:
‘如果大面积用DP, 可以把所有DP单独放到一个vbs文件中。脚本通过两种方式导入:
DPOR.vbs: |
Const dpBrowser = “micclass:=Browser” Const dpPage = “micClass:=Page” Etc |
10.1 Associate the VBS file on the Test Settings Resourcetab < fileàSettingà Resource >
10.2 Use the ExecuteFile statement to load the file intotest Actions
ExecuteFile“DPOR.vbs”
主题3:
Working with Multiple Browers:
Two browsers must use the index or Creation Time Propertyunique to each browser
Browser(“index=0”) OR Browser(“creationtime=0”)
But for multiple browsers may cause problems identifying by indexor Creation Time, can use OpenTitle or a unique OpenURL property
OpenTitle: initial title when the browser first launched
dpBrowser = "OpenTitle:=Google"
SystemUtil.Run "iexplore.exe","www.google.com"
Browser(dpBrowser).Navigate "www.gamil.com"
OpenURL: if two browser share the same OpenTitle property,then use OpenURL
browserID = RandomNumber.Value(10000,99999)
dpBrowser = “OpenURL: about” & browserID
SystemUtil.Run "iexplore.exe", "about: "& dpBrowser
Browser(dpBrowser).Navigate "www.gamil.com"