Skip to main content

Overview

Code execution steps let you run custom JavaScript in the browser during a test. This is useful when your test needs to interact with APIs, set up data, or perform actions that aren’t possible through the standard click/type/assert steps. The code runs in the browser context via page.evaluate(), so you have access to fetch(), document, window, and other browser APIs.

Adding a Code Execution Step

1

Open Edit Mode

Navigate to your test and click Edit Mode.
2

Add a Code Execution step

Click Add code execution between any two steps.
3

Write your code

Enter your JavaScript in the code editor. You can use top-level await — the code is wrapped in an async function automatically.
4

Set a description

Add a short description (e.g., “Upload file via API”) so the step is easy to identify in results.
5

Save

Click Save to add the step to your test.

Example

const response = await fetch(
  'https://api.example.com/upload',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ key: 'value' }),
  }
);

const data = await response.json();
console.log(data);

Timeout

Each code step has a configurable timeout (default: 30 seconds). If the code doesn’t finish within the timeout, the step fails. You can adjust the timeout in the step editor.

Behavior

  • Errors — If the code throws an error or times out, the step fails and the error message is shown in the test results.
  • Return values — If your code returns a value, it is captured and displayed in the step results.
  • Variable persistence — Variables declared with const/let don’t persist across steps. Use window.myVar = ... to share data between code steps.
  • Navigation — If your code navigates the page (e.g., window.location.href = ...), subsequent steps run on the new page.
Code execution steps are user-authored only — they cannot be generated by AI-based editing.

Need help? Contact our support team.