Script Extension: When does the 'extension loading into memory' event occurs?
Hi,
From https://support.smartbear.com/testcomplete/docs/working-with/extending/script/creating/initialization-and-finalization-routines.html : "The initialization routine of a script is executed when TestComplete loads the script extension in memory".
The question : does anybody know for sure (from one's experience) when the above event occurs? Does it occur when TestComplete starts and loads the given script extension into memory or when test execution starts or at some other moment of time?
The reason for the question : I am considering script extension that needs to have some internal variable to be initialized to zero on test execution start and keep changed value during test items execution within this test run.
Already existing regular script code uses (temporary) project variable that is assigned default value exactly on test run start.
I have some doubts that the same behavior is implemented for script extensions. Can anybody confirm/disapprove please ?
(Robert, Helen ?)
As a test, I created a script unit for a script extension with just the following:
var mySomething; function getMySomething() { return mySomething; } function setMySomething(value) { mySomething = value; } function Initialize() { mySomething = 'this is the initial value'; }
I encapsulated this into an extension with the following Description.XML
<ScriptExtensionGroup Name="TestThis"> <Category Name="TestThat"> <ScriptExtension Name="TestInitialization" Author="Robert Martin" Version="1.0"> <Script Name="testExtensionInit.sj" InitRoutine="Initialize"> <RuntimeObject Name="TestInit"> <Property Name="MySomething" GetRoutine="getMySomething" SetRoutine="setMySomething">Property description</Property> <Description>Runtime object description</Description> </RuntimeObject> </Script> <Description>Script extension description</Description> </ScriptExtension> </Category> </ScriptExtensionGroup>
I then wrote this code:
function blah() { Log.Message(TestInit.MySomething); TestInit.MySomething = 'New Value'; Log.Message(TestInit.MySomething); }
The first time I run this code after starting TestComplete I get a log that looks like this:
If I run it again without restarting TestComplete, I get the following:
So... the Initialization is executed at loading of TestComplete. The value in the variable persists beyond the test run so long as TestComplete has not been restarted.
If you want a variable value to be initialized in a script extension at the start of a test run, I believe you'll still need to call specific code to initialize the value.