Execute custom JavaScript or TypeScript code during your test flow.
execute javascript
interaction step allows you to execute arbitrary JavaScript or TypeScript code as part of your test flow.
This is useful for performing custom logic, calculations, or interacting with APIs that are not directly accessible through other test steps.
'execute javascript' interaction option in a test step, 05/2025
stderr
, the execute javascript
step fails.
context
object: context.variableName
return { variableName: value }
'execute javascript' interaction option executed in browser context, 07/2025
context
object:$$pageTitle
, $$userCount
, and $$currentUrl
.
setDynamicVariable
.
These variables can be used in subsequent steps of your test.
For example, if your script creates a new document in your application and receives a document ID in the response, you can expose this ID as a dynamic variable:
$$documentId
.
Example: Exporting a dynamic variable from a JavaScript step
getDynamicVariable
function.
For example, if you have a dynamic variable $$documentId
, you can use it in a step like this:
decrypt
function.
For example, if you have a secret template variable API_KEY
, you can use it in a step like this:
Example: Using a secret template variable in a javascript step
decrypt
function to decrypt the secret template variable in your test step.setDynamicVariable(name, value)
: Set a dynamic variable.getDynamicVariable(name)
: Get a dynamic variable.decrypt(name)
: Decrypt a template variable.console.log
function.
Example: Logging a message
throw
statement or output with console.error
will be considered as an error and the step will fail.
execute javascript
step, you can extend your tests with custom logic while maintaining security and reproducibility.