⚠️ Cleanup Steps are available on Advanced, Enterprise, or any other equivalent plans.
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.
When you go back to the Scenario tab, the Cleanup Steps section is added to the bottom of the screen.
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.
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.
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.
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
- If the scenario fails at Step 2, it will continue to run
The test result details page is divided into two parts: regular steps and Cleanup Steps. Here are some examples:
Successful test result
Failed test result with Cleanup Steps run
Even if regular steps failed in the middle, Cleanup Steps will run.
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.
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.
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.