Not Available on Windows XP and Windows Server 2003
var vs. let
let number = 5;
let number = 42; // This variable is different from the one above
let str = "test";
Log.Message(number); // 42
Log.Message(str); // "test"
Log.Message(number); // 5
Log.Message(str); // ReferenceError: str is not defined
You would typically use
let for variables local to a loop or a branch in
for (var i = 0; i < 5; i++)
// do something
// "i" is still visible here
When used outside functions, or at the top of a function,
let work in the same way.
var str1 = "hello";
let str2 = "world";
Log.Message(str1 + " " + str2);
Any variables declared without
let are implicitly global, as if they were defined outside of any function.
a = 5; // global variable
var b = 7; // local variable
Log.Message(a); // 5
Log.Message(b); // ReferenceError: b is not defined
Implicit global variables may have unwanted side effects in your code, so we recommend that you define all global variables explicitly.
===, may lead to incorrect results when comparing values obtained from:
- Objects in a tested application,
- TestComplete scripting objects (such as
- COM objects.
For example (but not limited to), when comparing these values to
undefined or objects.
|Instead of ...||Use ...|
In TestComplete, the properties of some test objects have parameters, such as
$set method instead:
// This won't work
gridObj.wValue(0, "Customer Name") = "Samuel Clemens";
// This works
gridObj.$set("wValue", 0, "Customer Name", "Samuel Clemens");
To get an indexed property with the default parameter values, use empty parentheses after the property name:
Working With COM Objects
getActiveXObject function. This function was introduced in TestComplete 12.4. It works faster than the
Sys.OleObject property that you used in earlier versions.
If you have multiple (more than several hundred) calls to methods and properties of COM objects, and you experience performance issues, you can use the special
$call methods (see below). They will make the calls faster. Otherwise, use the usual
object-name.method-name syntax. This way, your code will be easier to read and maintain.
$get, $set and $call
- Test objects (objects in your tested application),
- TestComplete scripting objects (
- COM objects.
Normally, you do not need to use these methods, only for assigning an indexed property (see above).
Referencing Other Script Units
You can use the
var answer = 42;
module.exports.hello = hello;
module.exports.answer = answer;
var common = require("CommonUnit");
//USEUNIT directive is also supported, but with some limitations.
instanceof operator returns an incorrect value if the checked objects are passed between script units. Suppose you have the following code:
throw new Error(10, "This is an error."); // Simulates exception
let res = err instanceof Error;
Log.Message("err instanceof Error = " + res);
fooB reside in the same script unit, the
res variable in the
fooB function will be
true. If you place
fooB to another unit, then the
res variable will be
In TestComplete, when the operand of the
typeof operator is a regular expression, you have to use parentheses:
Using Iterable Objects
You can use the
for...of loop to iterate over an iterable object:
for...of loop works with any test object that has the
_NewEnum property in the Object Browser.
Accessing Collection Items
COM objects can have properties that return a collection object. Some scripting languages like VBScript allow accessing collection items directly, for example,
obj.Cells(i, j) rather than
Passing Parameters by Reference
To work around this limitation, export the constructor of an object from the unit that contains the prototype method declaration. The code below demonstrates this approach:
var CommonUnit = require("CommonUnit")
// This won’t work:
let arr = new Array(6, 7, 8, 9);
arr.logIndexByItem(7); // Error: "The object does not support this property or method"
// This will work:
let arr2 = new CommonUnit.NewArray(1, 2, 3, 4, 5);
// Prototype method declaration
Array.prototype.logIndexByItem = function(item)
for (let i = 0; i < this.length; i++)
if ((i in this) && (equal(this[i], item)))
Log.Message("Item was not find");
// Exports the constructor of the modified Array object
exports.NewArray = Array;
debuggerstatement has no effect in TestComplete. To pause the script execution and activate the debugger, use the
If arrays and typed arrays contain many items, the debugger panels and dialogs group them by 100 for convenient presentation.