NisHera
11 years agoValued Contributor
A simple example of script extension to maintain common scripts
Hi
I need to maintain common scripts in one place and call those scripts in various tests.
For eg Log on , Cheking basic data for tests, cleaning after test... ect
In everywhere it says it could be done by implimenting script extension.
When I read through support litreture I'm overloaded with unwanted descrption of many things.
Any body could help me to find a simple example ?
Hi nishnatha, here is a simple example, please note, Test Complete does not handle Script Extension files that contain Unicode, for safety I always save files as ANSI
Save the following as example.js
var privateField = 123;
//<Property Name="ReadonlyField" GetRoutine="get_readOnlyField">
// A Readonly field.
//</Property>
var readonlyField = "I am Readonly";
function get_readOnlyField() {
return readonlyField;
}
//<Property Name="PublicProperty" GetRoutine="get_PublicProperty" SetRoutine="set_PublicProperty">
// A Public Property.
//</Property>
var PublicProperty;
function get_PublicProperty() {
return PublicProperty;
}
function set_PublicProperty( value ) {
PublicProperty = value;
}
//<Method Name="Func" Routine="func">
// Increments the private field and returns a message.
//</Method>
function func() {
privateField++;
return aqString.Format( "I incremented the Private field %i", privateField );
}
//<Method Name="FunctionWithParametes" Routine="functionWithParametes">
// Gets the result of adding a and b.
//</Method>
function functionWithParametes( a, b ) {
return a + b;
}
Save the following as Description.xml
<ScriptExtensionGroup>
<Category Name="Runtime Objects">
<!--
The following elements define a simple example script extension.
-->
<ScriptExtension Name="Example Script Extension" Author="Phillip Baird (c) 2014 ARC Innovations" Version="1.0" HomePage="http://www.arcinnovations.com/">
<Script Name="example.js">
<RuntimeObject Name="SimpleExample" Namespace="Example">
<Method Name="Func" Routine="func">
Increments the private field and returns a message.
</Method>
<Method Name="FunctionWithParametes" Routine="functionWithParametes">
Gets the result of adding a and b.
</Method>
<Property Name="ReadonlyField" GetRoutine="get_readOnlyField">
A Readonly field.
</Property>
<Property Name="PublicProperty" GetRoutine="get_PublicProperty" SetRoutine="set_PublicProperty">
A Public Property.
</Property>
<Description>
Example script Extension members.
</Description>
</RuntimeObject>
</Script>
<Description>
Example Script Extension.
</Description>
</ScriptExtension>
</Category>
</ScriptExtensionGroup>
Compress example.js and Description.xml into a zip file example.zip
Change the file extension of the zip file from example.zip to example.tcx
Close Test Complete if it is open
Copy the example.tcx to C:\Program Files (x86)\SmartBear\TestComplete 10\Bin\Extensions\ScriptExtensions (this path is dependant on your install)
Start Test Complete
In the intellisense, there will be a Namespace "Example" with a single Object "SimpleExample" that contains the members described in the Description.xml file
The following function shows how the Script Extension may be used
function useExampleScriptExtension() {
Example.SimpleExample.PublicProperty = "abc";
Log.Message( Example.SimpleExample.PublicProperty );
Log.Message( Example.SimpleExample.ReadonlyField );
Log.Message( Example.SimpleExample.Func() );
Log.Message( Example.SimpleExample.Func() );
Log.Message( Example.SimpleExample.FunctionWithParametes( 123, 456 ) );
}
Regards,
Phil Baird