exec
command. This feature, introduced in version 5.1.0
, enables you to integrate custom logic, such as generating one-time passwords (OTPs), hitting APIs, or performing other dynamic operations, directly into your tests.
Key features
- Run Node.js Scripts:
- Execute custom JavaScript code within your test steps.
- Use NPM modules to extend functionality.
- Dynamic Outputs:
- Store the result of your script in a variable for use in subsequent steps.
- NPM Support:
- Install and use NPM packages in your scripts.
Updated example: One-time password (OTP) validator
This example demonstrates how to generate a one-time password (OTP) using thetotp-generator
NPM package and use it in a test.
verify-otp.yaml
Additional details
- The
exec
command now takes alang
argument with supported valuesjs
orpwsh
. js
code is executed in a Node.js VM module internally.pwsh
code is executed in the PowerShell on the runner.
The
result
variable is already available in your script, overwrite it to store the output as shown in the example.The output
argument is assigned automatically by setting result = somestringvalue
in the script you run.Protips
- Always assign the output of your script to the
result
variable. - Ensure all required NPM packages are installed locally and in the
prerun
script when using GitHub Actions.