R. E. Cook
Home 
Contact Us 

Dr. Cook
Resume 

RunningShoes Library for WinRunner 
RunningShoes 

Custom WinRunner Functions 
and Utilities,
to Your Specs
Custom 

A Random Collection of WinRunner Solutions
Solutions 

Creating DLLs for WinRunner 
"DLLs Demystified" 
(Mercury Interactive's Worldwide Users Conference 2000)

R. E. Cook Consulting

 


Conditionally calling an initialization script


We normally call an initialization script from the test run's driver script, rather than from each of the individual scripts called during the test run. But for debugging a particular script, it is often useful to run the script by itself, not called by the driver. In order to ensure that all  initialization is properly handled regardless of whether the script is run by itself or is called from a driver, insert the following conditional code at the start and end of the script. No changes need to be made either to the driver or to any initialization scripts.

The purpose of the code is to call the initialization script only if the script is run by itself. The script determines this by checking the call chain: if the script has been called by another we know that at least one call is in the call chain. At the start of a script run by itself the call chain's depth is zero. The same logic holds at the end of a script, so we can call an uninitialization script to unload modules, etc., then exit the test with either a treturn() or a texit, as appropriate.

Place this code at the START of the script:

###############
# If script was not called, initialize the test setup.
###############

if(call_chain_get_depth() == 0)
   call_close "InitializationScript"();


Place this code at the END of the same script:

###############
# If script was called, return to calling script.
# Otherwise uninitialize the test setup.
###############

if(call_chain_get_depth() > 0)
   treturn(0);

else
{
   call_close "UninitializationScript"();
   texit;
}


Updated 25 October 2005



Top of  This Page | R. E. Cook Home Page

Copyright R. E. Cook Consulting, 2000 - 2011.
All rights reserved.

The site is designed to look best when viewed with Internet Explorer 5.0 - 8.0. Results with other browsers will probably deviate from what is intended.

NOTE: This website refers to registered trademarks and service marks that are owned by other companies, including Mercury Interactive, WinRunner, TestDirector, TSL, Microsoft, Windows.