You are here

Scripting

JavaScript and Python, and their simple differences

A note:

[DRAFT] Differences between Javascript and Python.

Beneeth describes a bit going through the syntax of code.

Syntax

Comments

Javascript

/*multiline
comment */
// one-line comment
var x = 1; // inside line comment

Python

"""Multiline comment
Only as docstring
"""
# one-line comment
x = 1 # inside line comment

Code Blocks

JavaScript uses curly brackets to denote code blocks.

Getting TestComplete to wait for a specific process lowering CPU usage

Sometimes while running tests, the CPU usage for a process (ie. tested application) can get higher than wanted. If the test get unstable due to this. The little trick can help you wait for more CPU power.

function TestProcessCPUUsage()
{
while(Sys.Process("chrome").CPUUsage > 5){
Delay(2000, "Chrome CPU usage: " + Sys.Process("chrome").CPUUsage);
}
}

Getting TestComplete to wait for more available CPU Power

Sometimes while running tests, the CPU usage can get higher than wanted. If the test get unstable due to this. The little trick can help you wait for more CPU power.

function TestCPUUsage()
{
// Will wait for the used CPU power to get below 5%
while(Sys.CPUUsage > 5){
Delay(2000, "CPU usage: " + Sys.CPUUsage);
}
}

Working with strings in TestComplete

Basics
A String is a sequence of symbols or digits. Strings are among the most frequently used data types. Like any other data type, strings in TestComplete are represented as OLE-compatible variants. In scripting, a sequence of literal characters, enclosed in double quotes ("), is recognized as a string. Single quotation marks (') are allowed within a string. To insert a double quotation mark into a string, it should be duplicated. The following is an example of string:

Scripting

str1 = "The buswas heading to London, when the driver noticed a cat on the road."
str2 = "'Ahoy! Is there anyone?' - the captain cried."
str3 = """Nobody."" - was the answer."

To work with strings, TestComplete has a special scripting object - aqString. The object is available for all supported scripting languages, so you can use it to work with string values regardless of the chosen language.