The exec command allows you to execute custom Node.js scripts within your TestDriver tests. This is useful for tasks like generating dynamic data, interacting with APIs, or performing custom logic during a test. The output of the script can be stored in a variable for use in subsequent steps. It’s important to note that the output from exec must be a string.
The language of the script to execute. Supported values are shell and js.
output
string
The variable name to store the result of the script. This variable can be accessed as ${OUTPUT.<var>} in future steps.
silent
string
Defaults to true. This is useful for suppressing unnecessary or private output in the test logs. If set to false, the command will print the output of the script. This is useful for debugging.
linux
string
The script to execute on Linux systems. For js, the script must define the output as result.
windows
string
The script to execute on Windows systems. For js, the script must define the output as result.
mac
string
The script to execute on macOS systems. For js, the script must define the output as result.
The exec command now takes a lang argument and supports different operating systems (linux, mac, and windows).
Supported lang values are js or shell:
js code is executed in a Node.js VM on the host machine (for example the machine where your CI/CD runs, or your computer if using the local agent).
shell code is executed in the shell on target runner (which can be the cloud runner, local sandbox, or local machine, depending on where you run your tests).
Note: You can also use shell in prerun scripts to install npm packages if you need them.
Otherwise, the shell code can be used within test steps to launch applications or perform simple commands (like writing text to a file on the machine to perform a simple file upload).
Code specified in linux, mac, and windows is executed based on the platform of the runner machine.
The outputargument is assigned automatically by setting result = somestringvalue in the script you run.
You can also save reusable snippets (like launching the calculator) to be inserted into a script later with the run command. That version would look something like this:
version: 5.5.5steps: - prompt: launch a calculator commands: - command: run file: ./launchcalculator.yaml - prompt: /try performing the operation 2 + 2 = on the calculator that is opened commands: - command: focus-application name: galculator - command: hover-image description: button with number 2 on the calculator action: click - command: hover-image description: plus button on the calculator action: click - command: hover-image description: button with number 2 on the calculator action: click - command: hover-image description: equals button on the calculator action: click