如何让你的QTP脚本执行效率更高?

上一篇 / 下一篇  2013-05-09 17:36:35 / 个人分类:QTP

Launch QTP using a .vbs file and not the QTP desktop icon. You will notice a substantial increase in speed. (使用VBS文件来启动QTP。) 
For large tests, always define variables, function in an external .vbs file and not inside a reusable action. Attach these files with your test scripts. If you define a variable or a function in an action, on every iteration of your test run, memory(RAM) will be allocated to those variables/functions and would not be released. Now as your script. starts consuming more and more RAM, your System Under Test (SUT) will tend to become slower. (把变量和函数定义放到外部VBS文件,而不要放在Action中。) 
While running, QTP consumes a lot of memory by itself. It is always advisable to have lots of available RAM( much more than what is recommended by HP) and good processor speed on a system where you intend to install QTP. When you have tests (and hence QTP) running for a prolonged period if time, there are chances of memory leaks. To avoid memory leakage always restart QTP at some intervals of time. Using AOM you can automate this process. (通过AOM控制QTP重启来解决QTP内存泄漏问题。) 
Avoid using hard coded wait(x) statement. Wait statement waits for full x seconds, even if the event has already occurred. Instead use .sync or exist statement. While using exist statement always have a value inside it. (尽量不要使用wait,而使用.sync或exist语句。) 
For ex: .Exist(10) Here QTP will wait max till 10 seconds and if it finds the object at (say) 3 secs , it will resume the execution immediately thereby saving your precious time. On the other hand if you leave the parenthesis blank, QTP would wait for object synchronization timeout you have mentioned under File > Test Settings > Run Tab.

Make full use of what HP-QTP has provided you in the tool IDE. Use “Automatically Generate “With” statements after recording” option present under Tools > Options > General Tab. This will not only make your code look neater but also make your scripts perform. better. (使用With语句可以让代码更清晰,而且效率更好。) 
Make your own judgement whether you want to go for Descriptive Programming or Object Repository or mixed approach. Each approach has it own pros and cons that in turn is related to QTP performance.(使用OR要比DP快点。) 
Unless absolutely required, uncheck the options “Save still image capture to results” and “Save movie to results” present under Tools > Options > Run tab. These options definitely have some bearing on QTP run time performance.(不要保存image和movie到测试结果中。) 
Make the Run Mode as “fast”. This setting is present under Tool > Options > Run tab. Note: If you intend to run your scripts from QC no need to worry about this option, as the scripts WILL run in fast mode whether you want or not. (把运行模式设置为fast。) 
If you are new to automation or QTP. Read this beginner article on Automation Object Model (AOM). AOM simplifies many aspects of QTP scripting. It can help you in controlling QTP from an external file. (通过AOM控制QTP。) 
Make use of relative paths while calling reusable actions in your script. Using relative path would make your script. portable and easy to manage. (在调用Action时使用相对路径。) 
 

可以使用下面的代码测试一下使用与不使用With语句在代码效率上的差异 :

Dim StartTime, EndTime, StartTime1, EndTime1

 

SystemUtil.Run "C:/Program Files/HP/QuickTest Professional/samples/flight/app/flight4a.exe"

 

With Dialog("Login")

.WinEdit("Agent Name:").Set "mercury"

.WinEdit("Agent Name:").Type micTab

.WinEdit("Password:").SetSecure "4864ede3f3f8f30757cf694e3e100d29bf1ea9b9"

.WinEdit("Password:").Type micReturn

End With

 

StartTime = Timer

For i=1 to 100

       Window("Flight Reservation").WinEdit("Name:").Set "Ankur"

Next

'With Window("Flight Reservation")

'For i=1 to 100

'.WinEdit("Name:").Set "Ankur"

'Next

'End With

EndTime = Timer

Print  EndTime - StartTime

 

 

 


在测试WEB应用程序时,往往看到QTP运行速度比被测试的应用程序要快很多,往往都是QTP在等待页面加载完成。


While working on a web applications using QTP, you may have noticed most of the time QTP runs too fast in comparison to the application. Moreover QTP would not perform. any operation on a particular page unless that page has loaded completely (100%). You may wonder in bewilderment about what to do to make the application (web page) load faster.

如何让页面加载得更快呢?关键在于图片的加载。

Here I would like to give you a simple tip to alleviate your pain (and waiting time) a bit.

If you will notice carefully, most of the times text on a web page renders very quickly. It is the images that creates problem and increases the web page loading time. What if we can stop the images from loading altogether?


All browsers provides this facility whereby you can stop pictures from showing. To do this in IE6, go to Tools > Internet Options > Advanced tab. Scroll down to ‘Multimedia’ section and uncheck ‘Show pictures‘.

 

To do this in Firefox, go to Tools > Options > Content. Uncheck ‘Load Images automatically‘


Run your script. now and let us know if this tip helped you. [For obvious reasons, this tip won't be of any use when you have to work on image/bitmap checkpoints.]

当然,如果考虑到图片检查点的话,这个技巧就没用了。

TAG:

 

评分:0

我来说两句

Open Toolbar