JavaScript step
The JavaScript steps allows you to execute JavaScript code. Asynchronous code usingasync
and await
is supported.
The output of the step is set to the final return value. This value must be
serializable (e.g. you cannot
return a class
or a function
).
{{ }}
expressions
Do not use
{{}}
expressions within JavaScript steps. There is no need to do
so since any variables and functions can be referenced directly.{{ env.USERNAME }}@gmail.com
, which might evaluate to something like
[email protected]
.
You should not include a return
statement in these expressions.
Execution context
By default, all code executes in an isolated Node.js sandbox. This ensures that one test’s code cannot access other users’ data, modify the test environment, or consume excessive resources. You can also execute the code in the current page’s JavaScript context by turn on the Execute in browser option. You will have access to globals likewindow
, document
, and other browser APIs. This is useful for interacting
with the page directly, such as manipulating the DOM or accessing
browser-specific features.
Globals
These globals are only available in the Node.js sandbox environment.
Third-party packages
axios
: For making HTTP/HTTPS requests. Please see the official documentation for usage and examples.assert
: For executing assertions based on variables and constants. Please see the official Node.js documentation for usage and examples.faker
: For generating mock data. Please see the official documentation for usage and examples.moment
: For creating and manipulatingDate
objects. Please see the official documentation for usage and examples.createAppAuth
: For authenticating with the GitHub API as a GitHub app. Please see the official documentation for usage and examples.Octokit
: For interacting with the GitHub API. Using this function may incur additional runtime. Please see the official documentationpg
: For interacting with PostgreSQL databases. Please see the official documentation for usage and examples.
Special utility functions
-
setVariable
: For setting a variable in the test context. Read more in Variables. -
sms
: For sending and receiving SMS messages. Read more in SMS. -
email
: For sending and receiving email messages. Read more in Email. -
ai
: For interacting with an LLM to generate text. Read more in Generating text. -
extractCookiesFromResponse
: For extracting cookies from a Response object, which is the type returned fromfetch
andaxios
calls. The cookies are returned in a format compatible with Playwright as well as the Load auth state step.