> 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/cleanup/cleanup-steps.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Cleanup Steps

{% hint style="info" %}
⚠️ Cleanup Steps are available on Advanced, Enterprise, or any other equivalent plans.
{% endhint %}

## Overview

Cleanup Steps are special steps that always run at the end of test execution even when the scenario failed in the preceding steps. This is very useful when you have steps that need to be run when the test finishes regardless of the result, such as deleting data generated during the test so that the next test will run under the same conditions.

## Enable Cleanup Steps

Cleanup Steps can be added to existing scenarios, however, they are hidden by default. To enable the feature, open the Options tab on the scenario details page and check Show Cleanup Steps.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-6d3a2507214cb3242cb3011adf43173b3d5539bf%2FScreen%20Shot%202023-08-27%20at%2021.30.58.png?alt=media)

When you go back to the Scenario tab, the Cleanup Steps section is added to the bottom of the screen.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-8f10a372f0317e9d5ae58b67c3ca2188082d360f%2FScreen%20Shot%202023-08-27%20at%2021.31.16.png?alt=media)

## Create Cleanup Steps

Cleanup Steps can be created in two ways:

### Drag and drop existing steps to mark them as Cleanup Steps

If you already have steps in the scenario that can be used as Cleanup Steps, you can drag and drop them into the Cleanup Steps area.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-648a5007eeb0678de5fc79a139d42aefc43e9006%2FScreen%20Shot%202023-09-15%20at%2011.05.25.png?alt=media)

### Record new steps as Cleanup Steps

Alternatively, you can also record Cleanup Steps from scratch. Note that the recording starts from the URL specified in Step 1 of the scenario. If you would like to start recording from a different URL, add a Go To step to the beginning of the Cleanup Steps.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-f9ae861b5a60166e8928669815525d3575b21595%2FScreen%20Shot%202023-09-15%20at%2011.04.43.png?alt=media)

## Run a scenario with Cleanup Steps

Scenarios with Cleanup Steps can run just as regular scenarios. However, how the steps will be run is different.

### Scenario

In the following example where Step 1 - 3 are regular steps (with the setting `When this step fails: Abort`) and Step 4 - 5 are Cleanup steps:

* If successful, the steps will be run in the order of `1` → `2` → `3` → `4` → `5`
* If the scenario fails at Step 2, it will continue to run `1` → `2` → `4` → `5`

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-c2723cb3aad300bf7a4c0700f581565b38f1dbd4%2FScreen%20Shot%202023-09-06%20at%2015.50.52.png?alt=media)

### Results

The test result details page is divided into two parts: regular steps and Cleanup Steps. Here are some examples:

#### Successful test result

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-5f0f91317d286d2304a905df4760ea1602d479a9%2FScreen%20Shot%202023-09-14%20at%2015.52.07.png?alt=media)

#### Failed test result with Cleanup Steps run

Even if regular steps failed in the middle, Cleanup Steps will run.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-d2d179c8b567c0ffc2b7a72ca4ac017dede072de%2FScreen%20Shot%202023-09-14%20at%2016.24.04.png?alt=media)

#### Failed test result with Cleanup Steps failure

It's also possible that Cleanup Steps may fail in the test. The test is considered to have failed, but the error message area is highlighted in yellow so that it's easy to make a distinction from a regular steps failure.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-a6c7b70336c3872a5622e3dd4f9339f03bf32d2c%2FScreen%20Shot%202023-09-14%20at%2016.25.14.png?alt=media)

## Tips

### Add Go To steps at the beginning

Cleanup Steps can work without a starting URL specified. Make sure to add a Go To step at the beginning if you want to make sure that Cleanup Steps start from a specific URL.

### Prepare an API endpoint to clear data

One of the best practices to clean up data created during tests is to prepare an API endpoint that clears your test data that can be called from a JS Step. Alternatively, you can simply record steps to delete or recover data by interacting with your application.

{% hint style="warning" %}
**Note**

Since this is an advanced feature provided for Advanced, Enterprise, or equivalent plans, Cleanup Steps will be hidden if you downgrade your contract plan to one where Cleanup Steps are not available.
{% endhint %}


---

# 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/cleanup/cleanup-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.
