testdriver/exec-shell.yaml
Description
Theexec command allows you to execute shell commands (Linux) or PowerShell commands (Windows) within your TestDriver tests. This is useful for launching applications, file operations, or performing system commands during a test.
Arguments
| Argument | Type | Description |
|---|---|---|
lang | string | The language of the script to execute. Supported values are sh (Shell/Linux) or pwsh (PowerShell/Windows). |
output | string | The variable name to store the result of the script. This variable can be accessed as ${OUTPUT.<var>} in future steps. |
code | string | The script to execute. |
silent | string | Defaults to false. The command will print the output of the script. This is useful for suppressing unnecessary or private output in the test logs and it’s useful for debugging. |
Example usage
This example demonstrates how to use theexec command to launch a calculator application.
calculator.yaml
Additional details
- Supported
langvalues areshorpwsh:shcode is executed in the shell on Linux sandboxes.pwshcode is executed in PowerShell on Windows sandboxes.- Note: You can also use
pwshin lifecycle scripts to install npm packages if you need them. - Otherwise, the
pwshcode 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).
- Note: You can also use
- The
outputargument captures stdout from your script.
Protips
- The
resultvariable is already available in your script, overwrite it to store the output as shown in the examples. - Do any handling of arrays or nested objects within your
jsscript:- ✅
result = users[1].profile.firstName - ✅
result = data.length > 0 ? data[0].userEmail : 'no user found'if no data is found the value of output will benull - ✅
result = someTestUserEmail - ✅
result = someTextToAssert - ✅
result = someDescriptionOfAnImageToScrollTo
- ✅
- Don’t try to pass any non-string values to
output:- ❌
result = [...users, ...values] - ❌
result = {name: "Dale Earnhardt", starts: 676, wins: 76} - ❌
result = [{user1: ...}, {user2: ...}]
- ❌
Ways to use exec
Here is an example using both pwsh and js contexts within a prerun.yaml script which creates a temporary email account and automatically clicks links found in received emails.
./lifecycle/prerun.yaml
Using exec pwsh commands in a test file
In a test file, you can use the pwsh context directly:
calculator.yaml
One more option
You can also save reusable snippets (like launching the calculator) to be inserted into a script later with therun command. That version would look something like this:
snippets/launch-calculator.yaml
calculator.yaml
Don’t try to run js within a test field
This example will fail at runtime, so don’t try to execute js context directly in a test file. Remember - use this in prerun to setup your test!
badtestfile.yaml

