QTP:是否可以创建一个在每次测试运行之前/之后执行的函数
是否可以创建一个在每次测试运行之前/之后执行的函数? 也许类似于这个。
例如,需要
- 在每次测试之前恢复到一个干净的数据库,
- 清除应用程序缓存或注册表设置之后每次测试
当然,可以创建2个函数并调用它们明确地出现在每个脚本的第一行和最后一行。然而,在一个地方定义它们一次是合适的,这样每次测试都会自动调用它们。
Is it possible to create a function to be executed before/after each test runs?
Maybe something like this.
For example, it is needed to
- revert to a clean db before each test
- clear application cache or registry settings after each test
Of course, it is possible to create 2 functions and call them explicitly in the first and the last line of each script. However it would be suitable to define them once in one place, so that they are invoked for each test automatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
免责声明。我不使用内置的 QTP 记录/播放框架或外部驱动程序。通过我自己的混合框架,我将测试逻辑与代码完全分离。因此我没有遇到所问问题中的问题。
根据提供的附加信息,我建议了一些可能的解决方法。
如果您已经在测试中使用了一些函数,例如 Init / Done,则可以将这些附加功能合并到其中。要指定确切要调用的函数,您可以使用例如 Dictionary 对象。作为此的子选项,请考虑使用回调。
如果您在测试中使用对象类,您可以将这些附加功能附加到自动调用的构造函数/析构函数中,因此您可以轻松地拥有多个退出点。在 VBScript 中,您只能通过委托来使用继承,但这应该足够了。这是关于 VBScript OOP 的示例。
您可以有一个特殊的“测试”脚本,由驱动程序在常规测试脚本之间调用。如果您的设置/恢复操作是通用的,那么这是一个“快速而肮脏”的解决方案。如果您计划使用各种设置/恢复操作,则需要考虑在特殊脚本中分派正确调用的方式。
Disclaimer. I do not use built-in QTP record/playback framework or external drivers. With my own hybrid framework I keep test logic completely separated from the code. Hence I didn't have such problem as in the question asked.
I suggest a few possible workarounds, based on the additional information provided.
If you already have some functions like Init / Done used in your tests, you can incorporate these additional functionalities within. To specify what exactly functions to call you may use, for example, Dictionary object. As a sub-option to this, consider using callbacks.
If you use object classes in your tests, you can attach these additional functionalities to constructors / destructors, which are called automatically, so you may easily have multiple exit points. In VBScript, you can use inheritance through delegation only, but that should be enough. Here's the example on VBScript OOP.
You can have a special "test" script, called by the driver in between of your regular test scripts. If your setup/recover operations are generic, that's a "quick-and-dirty" solution to go. If you plan to use a variety of setup/recover operations, you need to think of the way dispatching right calls in the special script.
根据您的情况,我会推荐阿尔伯特·加里耶夫建议的第二种选择。
只需在另一个 .qfl 库中创建一个类并为其创建一个访问器:
Add-And-Forget(tm):将库作为资源添加到您的测试中,您就可以忘记它。
In your situation I would recommend the second option that Albert Gareev suggested.
Just create a class in another .qfl lib and make an accessor to it:
Add-And-Forget(tm): Add the library as resource to your tests and you can just forget about it.