> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/javascript-steps.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# JS Steps

We like to say that we are a no-code solution. However, that does not mean that you can’t code! You can cover a broad spectrum of testing natively within Autify, but some of our clients have more advanced testing needs and want to go beyond Autify’s native capabilities; In those instances, clients can utilize JavaScript to greatly expand the scope of their testing.

## What is a JS Step?

***\[JS Step]*** is a function that allows you to execute JavaScript within Autify’s ***\[Scenario]***.\
This function enables capabilities that are unsupported by Autify’s standard functions.

Given its powerful nature, we have provided a detailed explanation below.\
After the section on how to use this function, you will find **specific use cases in the latter part of this article**. We hope they are useful!

{% hint style="warning" %}
**JS step will fail when a page is reloaded**

This failure happens because the page reload destroys the current execution context, leading to the loss of the JS step execution context.
{% endhint %}

## How to Add a JS Step in Your Scenario

1. Go to the **Scenario Details** Page where you want to add the **JS Step**
2. Move the cursor in between the steps where you want to add the **JS Step**

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-aad8e0ff4340d1ecb38eb2383baf22e6d8d7df09%2Finset-js-step\(1\).png?alt=media)
3. Click the **+** icon and and select **Insert Step**. Select **JS Step** from the menu that appears.

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-3007b70f3e724dc67e0716747d4a1f1c938f4780%2FScreen%20Shot%202022-07-21%20at%2018.22.07.png?alt=media)
4. Type your JavaScript code in the text editor. The code will already be wrapped in a function, so no need to include that syntax.

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-96c82feb2dc6b3a021be07be4158766f0097defb%2FScreen%20Shot%202022-06-13%20at%205.56.28%20PM.png?alt=media)
5. You can optionally name your **JS Step**, as well as include a Memo, such as a description of what is happening on this particular step

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-8b48c4760961db9599759d85e217977ba5a6cf2c%2FScreen%20Shot%202022-06-13%20at%206.07.15%20PM.png?alt=media)
6. Click **Save**

## Use a value obtained or generated in a JS Step in other steps

In ***\[JS Step]***, you can obtain information from elements displayed on the page or generate values. `return` allows you to use this information in subsequent steps. The actual `return` value can be seen on the test result.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-0fb75a7da19076ac483d45bcb0e424488365b905%2Freturn-value-en.png?alt=media)

If you have not `return` in JS step, this value will be `null`.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-206c933fcddb600fd54495762f4a0de619a82ff7%2Fnot-return-en.png?alt=media)

{% hint style="info" %}
Only **strings and numbers** can be used in subsequent steps.
{% endhint %}

### Used in the operation and assertion step

1. In the **Scenario Details Page**, click on the step you wish to insert the return value in
2. In the **Text to assign** dropdown, select **Other step's result** and select the desired **JS Step** whose data you wish to insert

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-e4ebede37940de74758133d7de6f7374573f269f%2Fjs-step-text-to-asign.png?alt=media)

### Use as Arguments of a JS Step

Values returned by a JS step can be used as arguments for other JS steps. Details are explained in the section "Using Arguments in JS Step" below.

## Using Arguments in a JS Step

1. Click on the thumbnail of the **JS Step**, which you want to pass in an argument for.
2. Click on the **+** icon within the parenthesis of the function

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-a63547ca8ed453c4bc7526e1eff490ccc57cf4eb%2Fjs-step-adding-arguments.png?alt=media)
3. Enter the name of your argument and click **Add**

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-513906eb7ec8d56cec40c74bd4996379f198c98b%2Fjs-step-arg-name.png?alt=media)
4. In the **Argument Values**, select the type of value you'd like to pass in
   * **Given value** allows you to hardcode in a string
   * [Test email address](https://help.autify.com/nocode-web/en/autify-university/advanced/email-testing-feature/email-test.md) allows you to select a pre-created test email address
   * [Data](https://help.autify.com/nocode-web/en/autify-university/foundation/creating-a-scenario/creating-data.md) allows you to select the columns of data in the scenario
   * **Other step's result** allows you to pass in the return value of a previous **JS Step** or [Dynamic Value](https://help.autify.com/nocode-web/en/autify-university/foundation/creating-a-scenario/dynamic-value-generation.md)
   * [Variable](https://help.autify.com/nocode-web/en/autify-university/advanced/variables/passing-variables-between-tests.md) allows you to select the key set in the **Import variables**

     ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-510feeefdc4e5be83d60683d6037a12af5fc1b96%2Fen-js-argument-value.png?alt=media)

{% hint style="warning" %}
**JS Step arguments are defined as String**

Even if you assign a numerical value to an argument in the UI, it is defined as a String in the code. You need to explicitly convert it to a Number if you want to use it in calculations. For instance, you can declare it with `Number()`.
{% endhint %}

5. To delete or rename an argument that has already been added, click on the target argument and make the necessary edits

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-ac7edb70fddf03761d2e3838e2d153f5d873a7e4%2Frename-arg.png?alt=media)

## JavaScript Snippets

For your convenience, we have compiled dozens of the most commonly used JS code snippets when testing with Autify; You can find a link to our JS Snippets [here](https://autify-javascript-snippets.netlify.app/).

### How to use JavaScript Snippets

1. Add a JS step to the scenario
2. In the Autify JS Snippet database, select the snippet you wish to use

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-591e9321deef9e02fd06dc162b7c9125809fd1f4%2FScreen%20Shot%202022-06-21%20at%205.39.07%20PM.png?alt=media)
3. Copy the JS snippet by hovering over it and clicking the "copy" icon on the top right corner of the snippet

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-bffb19049c90b731f79e0df7068a512ee0c12051%2FScreen%20Shot%202022-06-21%20at%205.40.44%20PM.png?alt=media)
4. Paste the snippet into your JS Step and make the necessary changes to the code to suit your test

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-662eee2e62c3ed15eb74b5279ca32da291be51fc%2FScreen%20Shot%202022-06-21%20at%205.44.10%20PM.png?alt=media)

## JS Steps Use Cases

There are many different ways you can use JS Steps to test with Autify. Here are some example use cases:

* API calls
* Handling cookies
* Custom assertions


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/javascript-steps.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
