Custom Code Steps
How to write and execute custom JavaScript code as test steps — for complex logic, calculations, and DOM interactions that go beyond natural language steps.
Quick answer
How to write and execute custom JavaScript code as test steps — for complex logic, calculations, and DOM interactions that go beyond natural language steps. Use this page to understand when the capability applies, complete its user-facing workflow, and verify the expected result.
What this page covers
Custom code steps let you write JavaScript that executes during test runtime. Use them for complex calculations, custom data transformations, direct DOM manipulation, or any scenario where a natural language instruction is insufficient.
Prerequisites
You have created or opened a test case.
You are familiar with the Test Steps Editor basics.
You have working knowledge of JavaScript.
Adding a custom code step
Open a test case and click Add Step.
In the step builder sidebar, select Custom Code.
Select JavaScript from the Language dropdown.
Write your code in the code editor.
Click Create Step to add the step to your test case.
Fields
Language
The scripting language. Currently supports JavaScript.
Code
The JavaScript code to execute at runtime.
Description
A plain-English summary of what the code does. Appears in the step list and execution report.
Example: Generate a unique identifier
Example: Calculate and verify a total
Example: Parse and transform data
Use an AI Ask result in custom code
An AI Ask action can save its answer to a runtime variable. A later Custom Code step can consume that value:
Add an AI Ask step, write a focused question, and set its output variable to a valid name such as
invoiceSummary.Place the Custom Code step after the AI Ask step.
Read the stored value by its exact, case-sensitive name—for example,
context.variables.invoiceSummary.Validate or parse the value before using it in a calculation or request.
AI output is generated text, so do not treat it as a trusted number, selector, command, or JSON object without validation. For an exact value already displayed in the DOM, use Store text from the element … into variable … instead of AI Ask.
Calculation and assertion pattern
For a calculation such as total = subtotal + tax, keep capture, calculation, and verification separate:
Store the displayed subtotal and tax in runtime variables.
Use Custom Code to parse the currency strings and calculate the expected total with the application's rounding rule.
Store or return the calculated value using the output supported by the selected Custom Code template.
Add a verification step that compares the displayed total with that expected value.
For a visual, non-critical check, an AI Verification prompt can read: Verify that the displayed Total equals Subtotal plus Tax, using two decimal places. For payment, ledger, or settlement validation, use an exact numeric assertion or API response validation instead of relying only on visual AI reasoning.
Advanced settings
Skip Step
Skip this step during execution without removing it from the test case.
Mark as Optional
If enabled, a failure on this step does not fail the overall test case.
Tips & best practices
Add a descriptive Description field so the step is understandable in the execution report without reading the code.
Keep code minimal. Custom code steps are for logic that natural language steps cannot handle. If a task can be described in plain English, use an AI Agent step instead.
Use custom code for data transformation between steps — formatting dates, calculating expected values, parsing complex response structures.
Avoid long-running operations. The step has a default timeout of 30 seconds. If your code needs more time, increase the step timeout.
Troubleshooting
Custom code step fails with a syntax error Check the browser console output in the execution report. JavaScript syntax errors surface as step failures with the error message in the step details. Validate your code in a browser console before pasting it into the step editor.
Variables from previous steps are not accessible Verify the variable name is spelled correctly and that the step that sets the variable runs before the custom code step. Variable names are case-sensitive.
Related pages
Last updated
Was this helpful?
