开发者

QTP: is it possible to create a function that will be executed before/after each test runs

开发者 https://www.devze.com 2023-02-08 02:45 出处:网络
Is it possible to create a function to be executed before/after each test runs? Maybe something like this.

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 开发者_Go百科they are invoked for each test automatically.


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.

  1. 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.

  2. 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.

  3. 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.


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:

private autoInitiatorTerminator : Set autoInitiatorTerminator = new cls_autoInitiatorTerminator

class cls_autoInitiatorTerminator

   private sub class_initialize
       ' put here your initiation code
   end sub

   private sub class_terminate
       ' put here your termination code
   end sub
end class

Add-And-Forget(tm): Add the library as resource to your tests and you can just forget about it.

0

精彩评论

暂无评论...
验证码 换一张
取 消