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 viapage.evaluate(), so you have access to fetch(), document, window, and other browser APIs.
Adding a Code Execution Step
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.Set a description
Add a short description (e.g., “Upload file via API”) so the step is easy to identify in results.
Example
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/letdon’t persist across steps. Usewindow.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.