让QTP运行速度更快的10条建议

上传人:ldj****22 文档编号:46507233 上传时间:2018-06-27 格式:PDF 页数:6 大小:138.74KB
返回 下载 相关 举报
让QTP运行速度更快的10条建议_第1页
第1页 / 共6页
让QTP运行速度更快的10条建议_第2页
第2页 / 共6页
让QTP运行速度更快的10条建议_第3页
第3页 / 共6页
让QTP运行速度更快的10条建议_第4页
第4页 / 共6页
让QTP运行速度更快的10条建议_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《让QTP运行速度更快的10条建议》由会员分享,可在线阅读,更多相关《让QTP运行速度更快的10条建议(6页珍藏版)》请在金锄头文库上搜索。

1、 让让 QTP 运行速度更快的运行速度更快的 10 条建议条建议 原作者:Ankur Jain 译者:Jeff、开心果、Wally 日期: 日期:2009-08-02 E 测中国翻译团队作品测中国翻译团队作品 E 测中国翻译团队首页:测中国翻译团队首页:https:/ 本文源自于某测试工具论坛上一个发人深思的问题:在那个帖子里,jpQTP 在寻找优化 QTP 脚本运行性能的方法。总所周知,我们使用自动化测试工具来改善测试过程。但如果没有合理规划使用工具并充分利用工具的各种功能是很难取得预期的效果的。 没有一个项目(自动化测试项目)是仅仅靠“录制-回放”就可以解决的。对任何测试工具,你都必须

2、深入掌握工具的原理。 测试工具好不好主要取决于测试人员用得好不好。 因此我认为这个问题将会是以后论坛上最好的问题之一。 以下是我在 QTP 脚本优化中的一些方法和技巧: ? 通过 VBS 脚本而不是图标启动 QTP,你会明显地感觉到速度的提升(关于如何通过VBS 启动 QTP,请参见早期的一个帖子) ? 对于大型项目的测试, 在一个外部的 VBS 文件里定义函数和变量, 而不是在一个可能被重复使用的 action 里定义。在测试脚本中可以加载这些文件。如果定义在action 里面,运行时每次迭代都会给这些对象分配内存,并且不会释放。这样运行的时候,脚本就会不断消耗内存,被测系统也会变得越来越慢

3、。 ? 运行的时候 QTP 自己就会消耗大量的内存,建议选择一台内存足够大(要远大于HP 推荐的标准),并且 CPU 足够快的机器来安装 QTP。当你的测试脚本(QTP)运行比较长的一段时间后,可能会出现内存泄漏。为了避免内存泄漏,每运行一段时间需要重启 QTP。AOM(Automation Object Model)可以自动化这一过程,可以参阅有关资料 ? 避免使用硬编码 wait(x)这种形式, wait 语句是一定要等到 x 秒以后才会执行下一步。建议使用 Sync 和 Exists 来代替。如果使用 Exist 方法的话,里面是有一个TimeOut 的参数的 例如:Exist(10)。

4、QTP 最多会等待 10 秒,但在这 10 秒里一旦条件满足,它会马上开始执行下一个步骤, 这样可以节约你的宝贵时间。 另外, 如果括号里没有参数,QTP 默认等待时间由选项“object synchronization timeout”决定。可以在File-Test Settings-Run 中设置。 ? 充分使用 HP-QTP 在 IDE 中提供的功能, 例如 With 语句: 使用选项 “Automatically Generate “With” statements after recording”,在 Tools-Options-General Tab 中设置。这个不但可以让你的脚本

5、看起来更美观,而且还可以改善你的脚本性能。 ? 根据不同情况选择描述性编程(Descriptive Programming)、对象库(Object Repository)或者混合模式编写脚本,这几种模式对 QTP 性能影响各有优缺点。 ? 除非有必要,否则不要选择“Save still image capture to results”和“Save movie to results”这两个选项,这在 Tools-Options-Run 中设置。这两个选项肯定会对 QTP 的运行性能造成一定的影响。 ? 将 Run Mode 设置成“Fast”。这在 Tools-Options-Run 中设置

6、。注:如果是在QC 中运行脚本则不用关注这个选项,这种情况下,系统始终是以“Fast”模式运行的。 ? 如果你刚接触自动化测试或是 QTP,阅读一下有关 Automation Object Model (AOM)入门文档。AOM 会帮你简化 QTP 脚本编程的很多问题。它能帮助你通过一个外部脚本文件来控制 QTP。 ? 在调用脚本中可复用的 action 时使用相对路径,使用相对路径可以使你的脚本便于移植和维护。 我会在我的下一个帖子中谈到为什么使用以及如何使用相对路径的一些细节。 你会如何优化你的脚本?请在下面留言。 原文: 原文: Make your QTP scripts perform

7、 better This post refers to a thought provoking question which was asked on Testing Tools forum. In this query jpQTP is looking for ways to optimize QTP scripts for best performance. Everyone knows we use automated testing tools to optimize our testing process. Unless you make full use of the capabi

8、lity of the tool and unless a tool is used sensibly and with proper planning, it would not yield any results. Just record-and-playback is never the solution for any project. You need to go deep inside to understand the intricacies of any tool. Any software testing tool is only as good as the test en

9、gineer using it. On those thoughts, I feel this was one of the best questions asked in the forums of late. Well, here are some of my tips and tricks to optimize the QTP scripts: Launch QTP using a .vbs file and not the QTP desktop icon. You will notice a substantial increase in speed. Refer the earl

10、ier post on How to open QTP using vbs file? ,you just need the 1st point of that post 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

11、 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. While running, QTP consumes a lot of memory by itself. It is always advi

12、sable 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 Q

13、TP at some intervals of time. Using AOM you can automate this process. If you want to go into details of effect of RAM on speed of computer read the post on RAM, Memory Usage thoroughly Avoid using hard coded wait(x) statement. Wait statement waits for full x seconds, even if the event has already o

14、ccurred. Instead use .sync or exist statement. While using exist statement always have a value inside it. 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 ha

15、nd if you leave the parenthesis blank, QTP would wait for object synchronization timeoutyou 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. 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 performa

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号