Scripts

Drop into Node, Python, or TypeScript for the steps that clicking cannot express.

Basic plan and above
View as Markdown

Some steps are not interactions. Generating a signed token, deriving a one-time code, reshaping a payload before the next request, computing a date three working days from now: these are jobs for a few lines of code, not a sequence of clicks. Scripts let you save that code once and call it from a step.

  1. 1The language: Node.js, Python, or TypeScript.
  2. 2When the script was last exercised, so a stale one is easy to spot.

Languages

Scripts can be written in Node.js, Python, or TypeScript. Manage them from Scripts in the sidebar, where each script has a name, a language, and its source. They are workspace-level, so one script can serve many tests.

Calling one from a test

Add a Script step and pick the script. It runs at that point in the flow, on Testsnag’s runners rather than in the browser, and can read the variables available to the run and write values back for later steps to use. That makes scripts the usual way to bridge two stages of a test that need a computed value between them.

Treat script source as shared code, not scratch space. Deleting a script that a test still calls will break that test’s next run, so check what references it before removing one.

Still stuck, or spotted something out of date?

Contact support