Scripting

Write JavaScript lifecycle scripts to set up test data, export reports, and send notifications. Available in both flow and load test specs.

Lifecycle Scripts

When Scripts Run

beforeAllScript

Runs once before the entire test or flow starts. Use for setup — register users, create test data, set flow variables.

afterAllScript

Runs once after the entire test or flow completes. Use for teardown — export reports, send notifications, clean up data.

Pre-Script / Post-Script

Run before and after each individual step. Use for dynamic headers, token extraction, and logging.

Note: All script types are available in both flows and load tests. Scripts are written in Tigrister Pro and executed by tgrs at runtime. For the full Scripting API reference, see the Scripting API section in the Tigrister Pro guide.

Setup with beforeAllScript

Register a User Before Testing

Use beforeAllScript to set up test data before the flow or load test starts.

// Register a user and store credentials for later steps

var baseUrl = tg.environment.get("base_url");

var res = await fetch(baseUrl + "/register", {

method: "POST",

headers: { "Content-Type": "application/json" },

body: JSON.stringify({

username: "{{random.string}}",

password: "{{random.string}}",

email: "{{random.email}}"

}) });

var data = await res.json();

tg.flow.set("username", data.username);

tg.flow.set("password", data.password);

console.log("Registered:", data.username);

Exporting Reports

Export in afterAllScript

tgrs does not have separate export flags — reports are generated and sent via afterAllScript. This gives you full control over where and how reports are delivered.

// Export HTML report and send to a server

var html = tg.export.html();

await fetch("https://reports.example.com/html", {

method: "POST",

headers: { "Content-Type": "text/html" },

body: html,

});

// Export PDF report

var pdf = await tg.export.pdf();

await fetch("https://reports.example.com/pdf", {

method: "POST",

headers: { "Content-Type": "application/pdf" },

body: pdf,

});

// Export JSON report

var json = tg.export.json();

await fetch("https://reports.example.com/json", {

method: "POST",

headers: { "Content-Type": "application/json" },

body: json,

});

Available Export Formats

tg.export.html()Interactive HTML report with embedded charts
tg.export.pdf()Printable PDF report (async — requires await)
tg.export.json()Structured JSON report for integrations

Available APIs

Script API Overview

Scripts have access to the following APIs. These are configured in Tigrister Pro when writing your pre/post scripts and lifecycle scripts.

APIDescription
console.log()Log messages during execution
tg.requestRead/modify request (url, method, headers, body)
tg.responseRead response (status, headers, body, json())
tg.flow.get() / set()Get/set flow variables that persist between steps
tg.environment.get() / set()Read/write environment variables
tg.export.html() / pdf() / json()Generate reports (afterAllScript only)
fetch()Send HTTP requests from scripts (lifecycle scripts only)

Limitations

Limitation: Top-level await and fetch() are only available in lifecycle scripts (beforeAllScript / afterAllScript). Pre/post scripts run synchronously — use flow variables for data passing between steps.