Cleanup Scenarios in TOSCA: Resetting Test Environments After Failures

Cleanup Scenarios

Table of Contents

Introduction

In automated testing, the ability to handle unexpected failures and maintain test stability is just as important as writing test cases. Tools like Tricentis Tosca have built-in mechanisms for recovery and cleanup that keep environments consistent. Among these, Cleanup Scenarios play a vital role.

Cleanup Scenarios

When test failures occur, Tosca’s Recovery Scenarios attempt to stabilize the environment by performing corrective actions. However, when even recovery fails, the test environment may remain unstable. That is where Cleanup Scenarios reset the environment to a clean, predictable state.

This blog explores Cleanup Scenarios in detail, using the saucedemo.com application as a practical example. We will cover success, recovery, and cleanup scenarios, explain the purpose of each, and demonstrate how they are configured in TOSCA Training sessions. Learners preparing for TOSCA Certification or an advanced TOSCA Automation Course will gain insights into how cleanup ensures reliable automation runs in real-world projects.

Why Cleanup Scenarios Matter

Modern software applications are complex. A simple UI test may involve browser sessions, login workflows, shopping carts, and checkout processes. Failures at any step can leave the environment in a state where subsequent tests cannot execute properly.

Imagine running a test to add an item to a shopping cart. If the recovery scenario cannot reset the cart, the next test may fail because the system state is already inconsistent. Cleanup Scenarios provide a reset mechanism to:

  • Restore application states
  • Reinitialize browsers or sessions
  • Remove residual data like cached logins or items in a cart
  • Guarantee fresh execution conditions for the next test run

In short, they ensure that one failed test does not impact the reliability of the entire suite.

Example Workflow: Saucedemo Checkout

To illustrate Cleanup Scenarios, let us use saucedemo.com as a test case. This application is widely used in TOSCA Training for practicing end-to-end workflows.

Steps in the Checkout Flow

  1. Open the URL: https://www.saucedemo.com/
  2. Login with valid credentials
  3. Click Add to Cart for a product
  4. Proceed to checkout
  5. Continue with the rest of the checkout steps
  6. Logout and close the browser

This workflow is considered the Success Scenario when every step executes correctly.

Success Scenario

The Success Scenario assumes the environment is ideal.

Cleanup Scenarios
  • Step: Click on Add to Cart.
  • Validation: The Add to Cart button is enabled and available to click.
Cleanup Scenarios

When executed, this confirms that the application is behaving as expected. In TOSCA Certification exams, candidates often practice creating such positive paths before moving to negative and recovery cases.

Recovery Scenario

A Recovery Scenario is invoked when the expected behavior does not occur. For example, on the product page:

  • The Add to Cart button may not be available.
  • Instead, the Remove button might be visible, indicating the item is already in the cart.
Cleanup Scenarios

Recovery Logic:

  • Verify that Remove is enabled.
  • If available, click Remove to reset the cart state.

This ensures that the cart is brought back to a clean condition, allowing the Success Scenario to proceed.

Cleanup Scenario

But what if the Recovery Scenario itself fails? For example:

  • The script checks that Remove is enabled.
  • Instead of passing, it fails due to misconfiguration, browser freeze, or element mismatch.

To test Cleanup Scenarios, you can intentionally force a failure by setting the validation to Enabled == False.Cleanup Scenarios in TOSCA: Resetting Test Environments After Failures This ensures that Tosca cannot complete the recovery step, which triggers the Cleanup Scenario.

Precondition: The Remove button is present on the inventory screen.
Trigger: The Recovery Scenario fails.
Cleanup Execution: Tosca runs the defined steps to restore the environment.

Cleanup Scenarios

Purpose of Cleanup Scenarios

1. Environment Reset After Failures

When a Recovery Scenario fails, the environment might be left partially logged in, with open browsers, incomplete sessions, or invalid data states. Cleanup Scenarios reset everything back to neutral.

2. Preventing Test Chain Reactions

In end-to-end suites, one failure can cascade into dozens of false positives if cleanup is not used. By enforcing a reset, each test case begins independently.

3. Enabling Continuous Execution

In DevOps and CI/CD pipelines, stability is essential. Cleanup provides a clean state for the next build execution, ensuring reliability in automated pipelines.

Illustrative Example

Let us consider the browser environment. A Recovery Scenario might attempt to close and reopen a browser tab but leave the session partially active. This inconsistency prevents the next test from running.

With Cleanup Scenarios, Tosca can:

  • Log the user out
  • Close the browser
  • Reopen the browser
  • Log the user back in
Cleanup Scenarios

This sequence guarantees a clean session for every test case.

How to Create a Cleanup Scenario in Tosca

Step 1: Access the Recovery Scenarios Folder

  • Open Tosca Commander.
  • Navigate to the Recovery Scenarios folder.
  • Right-click on the relevant folder.

Step 2: Initiate Cleanup Scenario Creation

  • Select Create Cleanup Scenario from the mini toolbar.
  • Tosca automatically generates a new cleanup container.

Step 3: Define Cleanup Steps

Add TestSteps to restore stability. Examples include:

  • Logout operations
  • Browser close actions
  • Application restart
  • Session reinitialization

Step 4: Configure Execution Conditions

Specify execution triggers. Tosca runs Cleanup only if:

  • The Recovery Scenario fails
  • The environment remains inconsistent

By default, Tosca retries the failed step after recovery. If that fails, Cleanup is executed.

Practical Example with Execution

Let us walk through the Saucedemo scenario:

Success Scenario Execution

  • Open URL
  • Login
  • Add to Cart
  • Checkout
  • Logout
  • Close browser

Recovery Scenario Execution

  • Add to Cart not available
  • Verify Remove is enabled
  • Click Remove

Cleanup Scenario Execution

  • Force failure by verifying Enabled == False
  • Tosca executes Cleanup
  • Logout user
  • Close browser
  • Restart browser
  • Login again

The result is a guaranteed reset before the next test begins.

Test Results

When running from the Execution List on the Execution Tab, Tosca reports:

  • Pass: If Success Scenario executes correctly
  • Recovery Executed: If Recovery fixed the failure
  • Cleanup Executed: If Recovery itself failed, and Cleanup restored the environment

This layered fallback ensures that no test run leaves the environment unstable.

Cleanup Scenarios

Cleanup Scenarios in TOSCA Training

During TOSCA Training, learners practice Cleanup Scenarios extensively because they simulate real-world failures. Test engineers encounter unstable states often, and cleanup skills are vital for passing TOSCA Certification and excelling in projects.

Benefits for Learners

  • Builds problem-solving skills
  • Strengthens understanding of error handling
  • Improves automation reliability
  • Prepares candidates for advanced topics in a TOSCA Automation Course

Industry Relevance

Organizations value testers who can design robust recovery and cleanup logic. This reduces flaky tests, accelerates CI/CD runs, and ensures business-critical workflows are validated reliably.

Best Practices for Cleanup Scenarios

  1. Keep Cleanup Independent
    Do not assume preconditions. Write Cleanup to handle any state.
  2. Use Minimal but Effective Steps
    Focus on restoring the environment, not duplicating recovery logic.
  3. Test Cleanup Explicitly
    Force failures during practice to ensure Cleanup works.
  4. Document Cleanup Steps
    Record what each step resets for future maintainers.
  5. Integrate with Test Strategy
    Treat Cleanup as part of the test lifecycle, not an afterthought.

Advanced Considerations

Cleanup in Large Suites

When hundreds of test cases run in parallel, Cleanup ensures independence. One test failing in a shopping cart should not impact another test validating login.

Cleanup with CI/CD

Pipeline automation relies heavily on environment resets. Cleanup supports test reruns and helps maintain green builds in continuous environments.

Reusability

Create generic Cleanup Scenarios (logout, close browser, relaunch) and reuse them across multiple test suites.

Key Takeaways

  • Cleanup Scenarios are critical for stable automated testing.
  • They execute when Recovery Scenarios fail, resetting the environment.
  • The saucedemo.com checkout process is a perfect example to practice cleanup.
  • Steps include logging out, closing browsers, reopening sessions, and resetting states.
  • For learners in TOSCA Training, mastery of Cleanup ensures readiness for TOSCA Certification and application in real-world projects.
  • A well-structured TOSCA Automation Course always includes scenarios to practice environment resets.

Conclusion

Failures in automation are inevitable, but instability should never carry forward. Cleanup Scenarios safeguard against cascading issues by resetting the environment after recovery failures. For anyone pursuing TOSCA Training, preparing for TOSCA Certification, or practicing in a TOSCA Automation Course, understanding cleanup is essential for building resilient automation frameworks.

Ready to take your testing skills further? Start practicing Cleanup Scenarios today and elevate your Tosca expertise.

Share this article

Enroll Free demo class
Enroll IT Courses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join Free Demo Class

Let's have a chat