QTP - 10. DP (Descriptive Programming) 描述性编程.

QTP - 10. DP (Descriptive Programming) 描述性编程

Writer : Tarun Lalwani

对象识别原理: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 expression 

Using Description Strings

2. Direct Way

 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"


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值