Converting Scripts From One Scripting Language To Another

Applies to TestComplete 14.60, last modified on April 22, 2021

Brief overview

The table below lists sample scripting statements that demonstrate syntactic differences between the scripting languages.

Case sensitivity

Sensitive

Sensitive

Procedure declaration

function MyProcedure()
{
  …
}

Function declaration

function MyFunction()
{
  …
  return 0;
}

def MyFunction():
  ...

Variable declaration

let x, y;
var x, y;

 

Constant declaration

const c = 45;

x = 0
y = 0

Boolean values

true false

True False

String literal

"String"
'String'

"String"
'String'
"""String"""

String concatenation

"Abra" + "cadabra"

"Abra" + "cadabra"

Comments

/* Multi-line
comment */

// Single-line comment

# Single-line comment

Assignment

x = 10;

x = 10

Object assignment

x = MyObject;

x = MyObject

Getting object property

x = obj.MyProperty;
x = obj.$get("MyProperty");

x = obj.MyProperty

Calling object method

x.MyMethod(Param1, Param2);
x.$call("MyMethod", Param1, Param2);

x.MyMethod(Param1, Param2)

Arithmetic operations

Addition

x + 5

x + 5

Subtraction

y - 9

y - 9

Multiplication

x * y

x * y

Division

x / 2

x / 2

Modulus arithmetic

x % 2

x % 2

Integer division

 

x // 3

Increment

i++
i = i+1

i += 1
i = i+1

Decrement

i- -
i = i-1

i -= 1
i = i-1

Exponentiation

Math.pow(x,3)

x ** 3

Comparison operators

Equality

x == 10

x == 10

Inequality

x != 0

x != 0

Less than

x < 17

x < 17

Greater than

x > 0

x > 0

Less than or equal to

x <= 5

x <= 5

Greater than or equal to

x >= 10

x >= 10

Test object equivalence

Obj1 == Obj2
equal(Obj1, Obj2)

Obj1 == Obj2

Logical operators

Logical negation

! x

not x

Logical conjunction

x && y

x and y

Logical disjunction

x || y

x or y

Logical exclusion

x ^ y

 

Bitwise operators

Bitwise negation

~ x

~ x

Bitwise conjunction

x & y

x & y

Bitwise disjunction

x | y

x | y

Bitwise exclusion

x ^ y

x ^ y

Bitwise left shift

x << y

x << y

Bitwise right shift

x >> y

x >> y

Conditionals

If statement

if (x == 10)
  Test1();
else
  Test2();

if x == 10:
  Test1()
else:
  Test2()

Switch/Select statement

switch (someChar)
{
  case "a": TestOnA(); break;
  case "z": TestOnZ(); break;
  default: TestOnElse();
}

if someChar == 'a':
  TestOnA()
elif someChar == 'z':
  TestOnZ()
else:
  TestOnElse()

Loops

For loop

for (let i = 0; i < 10; i++)
  Test1();

for i in range (0, 9):
  Test1()

While loop

while (i < 10)
  Test1();

while i < 10:
  Test1()

Do-While loop

do Test1(); while (i < 10)

while True:
  Test1()
  if i == 9:
    break

Enumerator loops

for i of object
— or —
Enumerator object
— or —
Utils.Enumerator() method

Utils.Enumerator method

Early exit from loop

break;

break

Arrays

Declare an array

let myArr = new Array(3);

myArr = []

Declare and initialize an array

let Arr = [10, 15, 25, 44];
let Arr = new Array(10, 15, 25, 44);

Arr = [10, 15, 25, 44]

Array length

len(myArr)
VarArrayHighBound(myArr,1)+1

Access array element

myArr[1] = 15;

myArr[1] = 15

Blanks

Verify if data is unassigned

strictEqual(x, undefined)
equal(x, aqObject.EmptyVariant)

x == aqObject.EmptyVariant

Test against empty object

strictEqual(myObj, null)

myObj == None
— or —
myObj == aqObject.EmptyObject

Check against blank value

strictEqual(myObj, null);

x == None

Handling exceptions

Handling exceptions

try
{
  Test1();
}
catch (e)
  Log.Error(e.description);

try:
  Test1
except:
  Log.Error(ExceptionMessage)

Sensitive

Sensitive

Sensitive

Insensitive

Insensitive

function MyProcedure()
{
  …
}

def MyProcedure():
  ...

Sub MyProcedure
  …
End Sub

procedure MyProcedure;
begin
  …
end;

function MyFunction()
{
  …
  return 0;
}

function MyFunction()
{
  …
  return 0;
}

def MyFunction():
  ...

Function MyFunction
  …
  MyFunction = 0
End Function

function MyFunction;
begin
  …
  Result := 0;
end;

let x, y;
var x, y;

var x, y;

 

Dim x, y

var x, y;

const c = 45;

var c = 45;

x = 0
y = 0

Const c = 45

const c = 45;

true false

true false

True False

True False

true false

"String"
'String'

"String"
'String'

"String"
'String'
"""String"""

"String"

'String'

"Abra" + "cadabra"

"Abra" + "cadabra"

"Abra" + "cadabra"

"Abra" & "cadabra"
"Abra" + "cadabra"

'Abra' + 'cadabra'

/* Multi-line
comment */

// Single-line comment

/* Multi-line
comment */

// Single-line comment

# Single-line comment

Rem Single-line comment 1
' Single-line comment 2

{ Multi-line
comment }
// Single-line comment

x = 10;

x = 10;

x = 10

x = 10

x := 10;

x = MyObject;

x = MyObject;

x = MyObject

Set x = MyObject

x := MyObject;

x = obj.MyProperty;
x = obj.$get("MyProperty");

x = obj.MyProperty;
x = obj["MyProperty"];

x = obj.MyProperty

x = obj.MyProperty

x := obj.MyProperty;

x.MyMethod(Param1, Param2);
x.$call("MyMethod", Param1, Param2);

x.MyMethod(Param1, Param2);
x["MyMethod"](Param1, Param2);

x.MyMethod(Param1, Param2)

Call x.MyMethod(Param1, Param2)

x.MyMethod(Param1, Param2);

x + 5

x + 5

x + 5

x + 5

x + 5

y - 9

y - 9

y - 9

y - 9

y - 9

x * y

x * y

x * y

x * y

x * y

x / 2

x / 2

x / 2

x / 2

x / 2

x % 2

x % 2

x % 2

x Mod 2

x mod 2

 

 

x // 3

x \ 3

x div 3

i++
i = i+1

i++
i = i+1

i += 1
i = i+1

i = i+1

Inc(i)
i := i+1

i- -
i = i-1

i- -
i = i-1

i -= 1
i = i-1

i = i-1

Dec(i)
i := i-1

Math.pow(x,3)

Math.pow(x,3)

x ** 3

x ^ 3

 

x == 10

x == 10

x == 10

x = 10

x = 10

x != 0

x != 0

x != 0

x <> 0

x <> 0

x < 17

x < 17

x < 17

x < 17

x < 17

x > 0

x > 0

x > 0

x > 0

x > 0

x <= 5

x <= 5

x <= 5

x <= 5

x <= 5

x >= 10

x >= 10

x >= 10

x >= 10

x >= 10

Obj1 == Obj2
equal(Obj1, Obj2)

Obj1 == Obj2

Obj1 == Obj2

Obj1 Is Obj2

Obj1 = Obj2

! x

! x

not x

Not x

not x

x && y

x && y

x and y

x And y

x and y

x || y

x || y

x or y

x Or y

x or y

x ^ y

x ^ y

 

x Xor y

x xor y

~ x

~ x

~ x

Not x

not x

x & y

x & y

x & y

x And y

x and y

x | y

x | y

x | y

x Or y

x or y

x ^ y

x ^ y

x ^ y

x Xor y

x xor y

x << y

x << y

x << y

 

x shl y

x >> y

x >> y

x >> y

 

x shr y

if (x == 10)
  Test1();
else
  Test2();

if (x == 10)
  Test1()
else
  Test2();

if x == 10:
  Test1()
else:
  Test2()

If x = 10 Then
  Test1
Else
 Test2
End If

if x = 10 then
  Test1
else
  Test2;

switch (someChar)
{
  case "a": TestOnA(); break;
  case "z": TestOnZ(); break;
  default: TestOnElse();
}

switch (someChar)
{
  case "a": TestOnA(); break;
  case "z": TestOnZ(); break;
  default: TestOnElse();
}

if someChar == 'a':
  TestOnA()
elif someChar == 'z':
  TestOnZ()
else:
  TestOnElse()

Select Case someChar
  Case "a" TestOnA
  Case "z" TestOnZ
  Case Else TestOnElse
End Select

case someChar of
  'a': TestOnA();
  'z': TestOnZ();
  else TestOnElse();
end;

for (let i = 0; i < 10; i++)
  Test1();

for (i = 0; i < 10; i++)
  Test1();

for i in range (0, 9):
  Test1()

For i = 0 To 9
  Test1
Next

for i := 0 to 9 do
  Test1

while (i < 10)
  Test1();

while (i < 10)
  Test1();

while i < 10:
  Test1()

Do While i < 10
  Test1
Loop

while (i < 10) do
  Test1();

do Test1(); while (i < 10)

do Test1(); while (i < 10)

while True:
  Test1()
  if i == 9:
    break

Do
  Test1
Loop While i < 10

repeat Test1(); until (i = 10);

for i of object
— or —
Enumerator object
— or —
Utils.Enumerator() method

Enumerator object
— or —
Utils.Enumerator() method

Utils.Enumerator method

For Each
— or —
Utils.Enumerator() method

Utils.Enumerator() method

break;

break;

break

Exit For
Exit Do

break;

let myArr = new Array(3);

var myArr = new Array(3);

myArr = []

Dim myArr(3)

var myArr : array[0..2];

let Arr = [10, 15, 25, 44];
let Arr = new Array(10, 15, 25, 44);

var Arr = [10, 15, 25, 44];
var Arr = new Array(10, 15, 25, 44);

Arr = [10, 15, 25, 44]

Dim myArr: myArr = Array(10, 15, 25, 44)

 

myArr.length

myArr.length
myArr["length"]
VarArrayHighBound(myArr,1)+1

len(myArr)
VarArrayHighBound(myArr,1)+1

UBound(myArr)+1
VarArrayHighBound(myArr,1)+1

VarArrayHighBound(myArr,1)+1

myArr[1] = 15;

myArr[1] = 15;

myArr[1] = 15

myArr(1) = 15

myArr[1] := 15;

strictEqual(x, undefined)
equal(x, aqObject.EmptyVariant)

typeof(x) == "undefined"
x == aqObject.EmptyVariant

x == aqObject.EmptyVariant

x = Empty
IsEmpty(x)
x = aqObject.EmptyVariant

x = Unassigned
x = aqObject.EmptyVariant

strictEqual(myObj, null)

myObj == null
— or —
myObj == aqObject.EmptyObject

myObj == None
— or —
myObj == aqObject.EmptyObject

myObj Is Nothing
— or —
myObj Is aqObject.EmptyObject

myObj = nil
— or —
myObj = aqObject.EmptyObject

strictEqual(myObj, null);

x == null

x == None

strictEqual(x, null)

x = nil

try
{
  Test1();
}
catch (e)
  Log.Error(e.description);

try
{
   Test1();
}
catch (e)
  Log.Error(e.description);

try:
  Test1
except:
  Log.Error(ExceptionMessage)

Err.Clear
On Error Resume Next
  Test1
If Err.Number <> 0 Then
  Log.Error Err.Description
End If

try
 Test1;
except
  Log.Error(ExceptionMessage);
end;

See Also

Script Tests
Supported Scripting Languages - Specifics of Usage
Handling Exceptions in Scripts

Highlight search results