Execute JavaScript command

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

Important: This command is available upon request. If interested, contact Perfecto Support.

Parameters

Name Type Possible values Description

Inline script *

String  

To perform custom logic execution using JavaScript. This could include but not limited to date/time formatting, manipulation of Strings, perform arithmetic operations, etc.

Here are some basic JavaScript syntaxes that can be used in the execute-Js command’s inline Js parameter:

Copy
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;
Tip: Avoid using comments (e.g., // todo or /* todo */) in the inline JS parameter.

Comment

String

 

Adds a comment to the script

On-fail Result*

Condition

Ignore | Break | Continue | Abort | Catch

The behavior when the command fails.

* Mandatory