TestDriver allows you to execute custom Node.js scripts and shell scripts within your test workflows using the 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

  1. Run Node.js Scripts:
  • Execute custom JavaScript code within your test steps.
  • Use NPM modules to extend functionality.
  1. Dynamic Outputs:
  • Store the result of your script in a variable for use in subsequent steps.
  1. 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 the totp-generator NPM package and use it in a test.
verify-otp.yaml
version: 6.0.0
steps:
  - commands:
      - command: exec
        lang: pwsh
        code: |
          npm install totp-generator
      - command: exec
        lang: js
        output: totp
        code: |
          const { TOTP } = require("totp-generator");
          let otp = TOTP.generate("JBSWY3DPEB3W64TMMQQQ").otp;
          console.log(otp);
          result = otp;
      - command: type
        text: ${OUTPUT.totp}

Additional details

  • The exec command now takes a lang argument with supported values js or pwsh.
  • 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 outputargument 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.