Skip to main content

How to use Init Scripts

Written by Ines

What are Init Scripts?

An Init Script is a snippet of JavaScript that runs in the browser before a page loads, so you can put the page into the right state before your test runs. It runs before every page that opens in the browser during a test run, and is configured per environment (e.g. a script on Staging runs only against Staging).

Common uses:

  • Bypass captcha

  • Force a feature flag on or off

  • Disable analytics so test traffic doesn't skew your metrics

  • Set the window or storage values the app reads on startup, for example to stop a cookie banner or overlay from appearing

How to add an Init Script

  1. Open your Test Project, go to Environments, and open the environment you want to configure.

  2. Select the Init Scripts tab.

  3. Click Add Script.

  4. Give the script a Name. This is how you'll recognize it later.

  5. Write your JavaScript in the Script editor.

  6. Click Save Changes.

Writing your script

The Script editor is a full code editor built for JavaScript:

  • Syntax highlighting and line numbers.

  • Live syntax checking: invalid JavaScript is underlined in red as you type, so you catch mistakes before saving.

  • A size counter in the top-right corner. Each script is limited to 10 KB; the counter turns red and saving is blocked if you go over.

You can reference your environment's variables, credentials, and app URLs directly in your script using the [VARIABLE] syntax. Thunders replaces each [VARIABLE] token with its value before the script runs.

  • Type [ in the editor to open an autocomplete list of the available variables.

  • Recognized variables are highlighted in the editor so you can spot them at a glance.

Seeing active scripts during a Test Execution

When you run a test against an environment that has one or more enabled Init Scripts, a badge appears at the bottom of the Test Steps list indicating that Init Scripts are active for the selected environment. This is a reminder that the page is being prepared before load.

Managing a script

Enable or disable a script

Each script has an Enabled toggle on its card. Turn it off to stop the script from running without deleting it. This is handy when you want to temporarily disable a behavior. The badge next to the list title shows how many scripts are active, for example 1/1 active.

Edit a script

Click the edit (pencil) icon on the script card, update the name or the script, then click Save Changes.

Delete a script

Click the delete (trash) icon on the script card, then confirm in the dialog.

Did this answer your question?