珍惜现在的每一分钟,全力以赴自己的梦想。 Jump for the sun, at least you land on the moon.

QTP描述性编程之我见(1)

上一篇 / 下一篇  2008-06-11 13:56:25 / 个人分类:测试技术

51Testing软件测试网[)?!`:Ip'L-y9p T

一直听说QTP描述性编程如何如何,亲自试了试,感觉说不上来,如果Mercury能够将ObjectRepository分类就好了,一类对象是录制脚本时候自动添加的object,另一类可能就是用户自定义或需要进行描述性编程时用到的手动添加的object。51Testing软件测试网MX0j1~t ^+_-n'H

51Testing软件测试网%t:x^2u`wUZ @

在动手之前,也去网上搜索了一些描述性编程的介绍,实例什么的,真到自己手动还真费了不少劲道。

\ {2XwO/zj+OSS!z0

$@X1pB N!d rWz*p!g M0下面是录制脚本和描述性编程脚本的对比片段:

@n"VxS051Testing软件测试网3KTh A7Gn

录制脚本:51Testing软件测试网+]K&KD-}t

k"Ui ` RoOh$j0'描述性编程51Testing软件测试网:jq!t-`+d:D3S)`
Browser("Google").Page("Google").WebEdit("q").Set "losing the love"
0BHI;v@O\0Browser("Google").Page("Google").WebRadioGroup("meta").Select "lr=lang_zh-CN|lang_zh-TW"
C?x:a-\0rI0Browser("Google").Page("Google").WebButton("Google 搜索").Click

sl;r0[W4v(H/AV0

M(lA'E f1j0l#J%C Q Z%D0描述性脚本:51Testing软件测试网$H#cP;`2?!t

RM [Y B^4]iZ4r[I0'描述性编程51Testing软件测试网$y.}Z$|0n%g`c
Browser("title:=Google").Page("title:==Google").WebEdit("name:=q").Set "losing the love"51Testing软件测试网#R} EBz
Browser("title:=Google").Page("title:=Google").WebRadioGroup("name:=meta").Select "lr=lang_zh-CN|lang_zh-TW"51Testing软件测试网Gk#L6h;G
Browser("title:=Google").Page("title:=Google").WebButton("name:=Google 搜索").Click51Testing软件测试网1Z,wT"d,h3sc bUB

51Testing软件测试网AO{5Rl1E8V

大家注意上述代码中的红色文本,如果有过开发经验的测试人员更容易理解,ms描述性编程就是将对象用属性来描述,并且描述的属性还必须唯一,否则QTP就无法正确识别。

B Y ]sC%G} X vA4i9S3h0

,cA'D S?.dY)WTQ0接下来就说说描述性编程的语法了:

B@%p u5@U}0

|/Qf^B"jUr*D0对象0("属性名0:=值0",..."属性名n:=值n").~对象m("属性名0:=值0",..."属性名n:=值n")51Testing软件测试网'koI(X6{,O

51Testing软件测试网@"yn u[KS

注意:51Testing软件测试网9]'S \l/g"JQ'`p
1)如果需要两个以上特性来描述一个对象,需要使用逗号(,)对描述性语言进行分割;
q MxW U(e c IQ02)使用:=来连接属性和属性值,并且:=两边不能有空格;
/AE2^t*C O|03)使用SPY或ObjectRepository查看对象的属性名和值;

9d8w6z/HwX0

oBE@ W#}0另外,如果能够事先取得某属性的值并以变量的形式出现,那么在使用描述性编程的时候就能够更加的灵活了。如:

&Fn2z.j~)r)}*w:lc$cy0

F^"nJ%P0Dim BrowserTitle, PageTitle, SearchKeyWords
!J)u'`-K*k ~L9cRP0BrowserTitle="Google"51Testing软件测试网3A4v"wS1t
PageTitle="Google"51Testing软件测试网u1whU7ajO
SearchKeyWords="Losing the Love"51Testing软件测试网6V sFs1yb+H!v ^g
Browser("title:=" & BrowserTitle).Page("title:" & PageTitle).WebEdit("name:=q").Set SearchKeyWords51Testing软件测试网 M OP i C u2^

51Testing软件测试网"P:?{&j t ~ S^

http://www.51testing.com/html/51/133.html51Testing软件测试网;Xebxl#^cj


TAG: 小樱原创 测试技术

温暖在人间 引用 删除 love0523   /   2009-05-15 14:42:33
 

评分:0

我来说两句

Open Toolbar