Execute custom shell or Node.js scripts within your tests.
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
.
Argument | Type | Description |
---|---|---|
lang | string | The language of the script to execute. Supported values are pwsh 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. |
code | string | The script to execute on Windows systems. For js , the script must define the output as result . |
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. |
exec
command to generate a TOTP (Time-based One-Time Password) using the totp-generator
library.
lang
values are js
or pwsh
:
js
code is executed in a Node.js VM internally on the host machine (for example the machine where your CI/CD runs, or your computer if using the local agent).pwsh
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).
pwsh
in lifecycle scripts to install npm packages if you need them.pwsh
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).output
argument is assigned automatically by setting result = somestringvalue
in the script you run.result
variable is already available in your script, overwrite it to store the output as shown in the examples.js
script:
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 be null
result = someTestUserEmail
result = someTextToAssert
result = someDescriptionOfAnImageToScrollTo
output
:
result = [...users, ...values]
result = {name: "Dale Earnhardt", starts: 676, wins: 76}
result = [{user1: ...}, {user2: ...}]
exec
pwsh
and js
contexts within a prerun.yaml
script which creates a temporary email account and automatically clicks links found in received emails.
exec
pwsh commands in a test filepwsh
context directly:
run
command. That version would look something like this:
js
within a test fieldjs
context directly in a test file. Remember - use this in prerun
to setup your test!