Forum Discussion

AlexKaras's avatar
AlexKaras
Champion Level 3
8 years ago
Solved

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 execut...
  • tristaanogre's avatar
    8 years ago

    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.