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. The easiest way to add a code step is during a Chrome extension recording. The code runs immediately so you can verify it works before saving.
1

Start a recording

Open the Decipher Recorder sidebar and click Record Tab to begin recording your user flow.
2

Click Add Code Step

In the recording sidebar, click the + Add Code Step button. This appears between the action log and the “Watching…” indicator.
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. A template with a fetch example is pre-filled to get you started. Use return to pass a value back — it will be shown in the step results.
4

Add a description

Describe what the code does (e.g., “Create test user via API”). This description appears in the action log and in the generated test steps.
5

Run & Add Step

Click Run & Add Step. The code executes immediately in the page. You’ll see whether it succeeded or failed, along with any return value. The step is added to your recording’s action log with before/after screenshots.
6

Continue recording

Keep recording the rest of your flow. When you generate a test, the code step is included at the correct position in the test.
If a code step fails, the error is shown but your recording continues. Delete the step and try again with corrected code.

Adding in Edit Mode

You can also add code steps to an existing test:
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 and save

Enter your JavaScript, set a description and timeout, then click Save.

Example

const response = await fetch(
  'https://jsonplaceholder.typicode.com/posts',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ title: 'Test Post', body: 'Hello', userId: 1 }),
  }
);

const data = await response.json();

// Return a value to see it in the step results
return data.id;
The last expression returned by your code is captured and displayed in the step results, so you can verify the step did what you expected.

Timeout

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

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.