51Testing软件测试论坛
标题:
[翻译]The Fastest Way to Work with GUI Objects
[打印本页]
作者:
asoqa
时间:
2009-2-12 21:02
标题:
[翻译]The Fastest Way to Work with GUI Objects
尝试翻译一下,翻译不好的地方请大家多多见谅。
原文地址:
http://www.advancedqtp.com/knowledge-base/articles/qtp-tricks4/the-fastest-way-for-working-with-gui-objects/
译文如下:
那么,什么是操作GUI对象最快速有效的方式?仁者见仁、智者见智 – 一些人拥护对象库(OR),而另一些人则强烈推荐描述性编程(DP)。有的人会将每个对象赋值给一个变量并使用,有的人会直接使用对象库中的对象,认为这才是最有效的方式。
实验
好的,我认为我们最好整理一下两种方式,并进行科学的(或多或少)实验:
1. 测试对象为Google首页搜索页面上的查询框。
2. QTP被设置为Fast运行模式,智能识别被关闭。
3. 只有一个浏览器打开,并且对应网页只保证一个打开。
4. 测试环境:运行在VMWare Fusion 2.1上的虚机IE7,Windows XP SP3 ,1GB内存。测试实机为2.4GHz MacBook(共4GB内存)
5. 测试运行10次,取其平均值
6. 通过以下方式操作GUI对象:
a) 常规方式使用对象库(OR)
b) 直接使用描述性编程(DP)
c) 变量引用方式的OR(将OR对象赋值给一个变量,再使用此变量)
d) 变量引用方式的DP(类似c))
e) 运行时OR(使用对象库访问WebEdit运行时对象,并通过改变运行时属性的方式设值)
f) 运行时DP(类似e))
g) 运行时变量引用OR(使用对象库访问运行时对象,将其赋值给一个变量,再使用此变量)
h) 运行时变量引用DP(类似g))
7. 每个方法一个for循环连续输入50个数据。
我认为上面的方法已经很好的覆盖了所有主流操作GUI对象的方式。每个循环之前会加入时间戳,并与循环后的时间戳比较。
这里给出测试代码:
Dim i
Dim iTimer
Dim oEdit
'常规方式使用对象库
iTimer = Timer
For i = 0 to 50
Browser("Google").Page("Google").WebEdit("q").Set i
Next
Print "Regular OR =" & (Timer - iTimer)
'描述性编程
iTimer = Timer
For i = 0 to 50
Browser("index:=0").Page("index:=0").WebEdit("name:=q").Set i
Next
Print "Descriptive Programming =" & (Timer - iTimer)
'变量引用方式的OR
iTimer = Timer
Set oEdit = Browser("Google").Page("Google").WebEdit("q")
For i = 0 to 50
oEdit.Set i
Next
Print "OR via fixed reference =" & (Timer - iTimer)
'变量引用方式的DP
iTimer = Timer
Set oEdit = Browser("index:=0").Page("index:=0").WebEdit("name:=q")
For i = 0 to 50
oEdit.Set i
Next
Print "Descriptive programming via fixed reference =" & (Timer - iTimer)
'运行时OR
iTimer = Timer
For i = 0 to 50
Browser("Google").Page("Google").WebEdit("q").Object.value = i
Next
Print "Runtime through OR =" & (Timer - iTimer)
'运行时DP
iTimer = Timer
For i = 0 to 50
Browser("index:=0").Page("index:=0").WebEdit("name:=q").Object.value= i
Next
Print "Runtime through Descriptive Programming =" & (Timer - iTimer)
'运行时变量引用OR
iTimer = Timer
Set oEdit = Browser("Google").Page("Google").WebEdit("q").Object
For i = 0 to 50
oEdit.value = i
Next
Print "Runtime through OR fixed reference = " & Timer-iTimer
'运行时变量引用DP
iTimer = Timer
Set oEdit = Browser("index:=0").Page("index:=0").WebEdit("name:=q").Object
For i = 0 to 50
oEdit.value = i
Next
Print "Runtime through DP fixed reference = " & Timer-iTimer
复制代码
更新:
Dani提供了一种不同的方式访问运行时对象,通过getElementById/Name方法:
'Runtime through the OR and GetElementById
iTimer = Timer
Set we = Browser("Google").Page("Google").Object.getElementById("id")
For i = 0 to 50
We.Value = i
Next
Print "Runtime through the OR and GetElementById" & Timer-iTimer
'Runtime through the OR and GetElementByName
iTimer = Timer
Set we = Browser("Google").Page("Google").Object.getElementByName("name")
For i = 0 to 50
We.Value = i
Next
Print "Runtime through the OR and GetElementByName" & Timer-iTimer
复制代码
结果
这里给出的是平均结果:
常规方式使用对象库(OR) = 5.59375
直接使用描述性编程(DP) = 6.375
变量引用方式的OR = 3.31253
变量引用方式的DP = 3.25122
运行时OR = 2.90625
运行时DP = 3.921875
运行时变量引用OR= 0.203125
运行时变量引用DP = 0.265625
更新: Runtime through GetElementById = 0.20122; and through GetElementByName = 0.21019
这个结果有点让人吃惊,至少对我来说。但是本质是一样的-运行时变量引用的方式是最有效的方式。
从结果看直接访问对象库比描述性编程要快(相差近一秒-个人而言,这非常让我震惊)。使用OR和DP访问WebEdit运行时对象的时候,这个差距被进一步拉大,已经超过1秒。然而使用中间变量时,两者的区别却微乎其微。
值得注意的是,使用运行时对象减少了近一半时间,接近使用变量索引方式下的性能。
最后的赢家,是运行时变量引用的方式。这并不奇怪,这种方式完全回避QTP GUI的对象匹配机制(包括一开始的变量赋值)。
我希望你能欣赏这篇文章,我希望能听到更多关于在QTP上执行脚本的性能和其他测试的主意(而不是QTP本身)。
[
本帖最后由 asoqa 于 2009-2-12 21:07 编辑
]
作者:
假装不在
时间:
2009-2-13 08:50
http://www.51testing.com/?174770 ... e_itemid_90151.html
【运行速度】对象库 与 描述性::yiwusuoyou::: ::yiwusuoyou:::
作者:
假装不在
时间:
2009-2-13 08:58
我觉得作者还研究少了快的原因,或者只叫猜测...
作者:
heqingbluesky
时间:
2009-2-13 16:44
已经读过这篇文章,在adavancedqtp网站。
LZ还可以翻译另外一篇对于应用Class和Function的速度,也很有意思的,可以更进一步了解OO编程。
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2