Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Different Ways to exit from a QTP test: Using ExitTest, AOM and LoadandRunAction

In QTP, Framework should ensure that test is exited as soon test is failed, since there is no point in going forward with execution.
To ensure proper exit from QTP test, we can either use error handling using recovery scenario or vb script. In case of error handling using vbscript, we can exit a test at runtime in following ways.


Using ExitTest Statement

ExitTest statement exits a test once executed in script.But in scripts with functions called from other functions in different libraries and in case if there is multiple nesting of functions within different libraries, ExitTest statement on execution does not stop the test execution.
To understand this, suppose there is Test A and there are 4 different libraries(vbs files) f1,f2,f,3,f4  in which functions are stored and the action in Test A calls function from library f1 which further calls function from library f2 ans so on. In such cases, sometimes exitTest does not get executed and moves to next test without exiting the test.
To exit from test in scenario where ExitTest is not working properly, we can exit from test in below ways:


 Using QTP AOM

 Use following code to exit test in case exitstatement is not working.
Dim qtAppObj
Set qtAppObj = CreateObject("quicktest.application")
qtAppObj.Test.Stop

Using LoadandRunAction

Create a test with Action  Action1. In Action , only write ExitTest. Save the test.
Now in the test, where exitTest is not working properly, instead of ExitTest, write below code:

LoadandRunAction "c:\Test1","Action1"

Once this line of code is executed, QTP will exit the test.

Please go through the below posts for understanding of :

How to execute multiple external tests action using LoadandrunAction from QTP test

In QTP, we can execute external tests actions from a QTP test using LoadandRunAction Method. This method was introduced Post QTP 10, and is very useful to execute multiple tests from a test.Using This method we can execute reusable actions.


Syntax for LoadandrunAction is:



LoadAndRunAction "C:\Documents\qtp\test", "Action1", oneIteration


This will load Action1 from test in the script in which it is called.

Benefits of LoadandRunAction  are as follows:


  • Loads Action from external test dynamically at run time.

  • Can be useful to execute multiple tests in batch from the driver script which will call multiple tests action using LoadandrunAction

  • To run a test from QC, Test Path starts with [QualityCenter] Subject followed by folder structure in QC e.g "[QualityCenter] Subject\TestAutomation/Module1/Test1"



How to share values between various actions in a test in QTP


Below are the various ways by which values can be transferred between various actions in a test.

Sharing Values via the Global Data Table

Value generated in one action can be shared  with other actions in your test by storing the value in the global Data Table. Each Action in the test can access the global data table and hence can access data from the global data table. For details on how to access various in a data table, see Working With data Tables in QTP


Sharing Values Using Environment Variables

Environment variables are also shared between actions and can be used to share information between various action in the test. Also values can be parameterized using environment variable. To create an environment variable, loading environment variable, and details on environment variable, Please see post on Environment Variables in QTP

Sharing Values Using the Dictionary Object

Values between various actions in a test can be done creating a global dictionary object, and using properties of dictionary object.Below are the steps to share values between actions using globaldictionary object:

To use the Dictionary object, you must first add a reserved object to the registry (in HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\) with ProgID = "Scripting.Dictionary". For example: HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary


Once object has been added, we can add and remove values to the Dictionary in one action and retrieve the values in another action from the same test using scripting dictionary methods.For details on Scripting Dictionary, Please see Working with dictionary Object