Execute JavaScript command

Uses Javascript for executing tests, for example to auto-generate a job number for each job run.

Important: This command replaces the Execute TCL Script command, available in select cloud environments, which is being deprecated.

Parameters

Name Type Possible values Description

Inline script*

String

 

Runs custom logic using JavaScript. This could include, but is not limited to, date/time formatting, manipulation of strings, and arithmetic operations.

Avoid using comments (such as // todo or /* todo */) as part of the Inline script parameter value.

Following are some basic examples you can use:

Copy
Basic examples
const sqRoot = Math.sqrt(16);
const currentDate = new Date();
const futureDate = new Date(currentDate.getTime() + 1000 * 60 * 60);
const pastDate = new Date(currentDate.getTime() - 1000 * 60 * 60);
const isFutureDate = futureDate > currentDate;
const isPastDate = pastDate < currentDate;
const str1 = 'hello';
const str2 = 'world';
const stringComprision =  str1 === str2;

You can also integrate this parameter with Scriptless Mobile variables, as follows:

  • To read from an existing variable called firstName, include the following:

    Copy
    getTestVariable("firstName");
  • To save a value to an existing variable called zipCodes, include the following, where zip is a variable inside the JavaScript code and assigned to a Scriptless Mobile variable called zipCode.

    Copy
    setTestVariable ("zipCode", zip);
Copy

Examples using variables

const sqRoot = Math.sqrt(16);
setTestVariable ("JS_VAR", sqRoot)

const sentence = "The quick brown fox jumps over the lazy dog. The fox is quick!";
const newSentence = sentence.replace(/fox/g, "cat");
setTestVariable ("JS_VAR_2", newSentence)

const sqRoot = Math.sqrt(getTestVariable("myNum"));
setTestVariable ("mySqRoot", sqRoot)

Comment

String

 

Adds a comment to the script

On-fail Result*

Condition

Ignore | Break | Continue | Abort | Catch

The behavior when the command fails.

* Mandatory