Skip to content

Setup and Teardown in Robot Framework Explained

30-09-2026 Roy de Kleijn
Setup and Teardown in Robot Framework Explained

Every test should start from a known state and leave the world tidy when it finishes. Setup and teardown are how Robot Framework does both, and understanding them will save you a lot of flaky tests.

The idea

Setup runs before a test, to prepare what it needs. Teardown runs after, to clean up. The important guarantee is that teardown runs even when the test fails, so your cleanup always happens. That is what stops one broken test from leaving a browser open or a record behind that breaks the next one.

Three levels

You can attach setup and teardown at three levels, and choosing the right one is most of the skill:

  • Suite runs once for the whole file, ideal for expensive, shared preparation like opening a browser.
  • Test runs around every test, the natural home for per-test state and for capturing a screenshot when a test fails.
  • Keyword travels with a keyword, so cleanup stays next to the thing that needs it.
*** Settings ***
Suite Setup      New Browser    chromium
Test Teardown    Take Screenshot If Test Failed
Suite Teardown   Close Browser

Why it matters

Reliable cleanup is one of the foundations of a suite that does not turn flaky as it grows. Getting the levels right, and combining them with browser contexts for isolation, is part of building web tests that stay green. Our Robot Framework Certified Professional course covers setup and teardown alongside the Browser library and reporting, and prepares you for the RFCP exam.

Frequently asked questions

Does teardown run if the test fails? Yes. That is the point. Teardown runs whether the test passes or fails, so cleanup is reliable.

What is the difference between suite and test setup? Suite setup runs once for the whole file. Test setup runs before every test. Use suite setup for shared, expensive preparation and test setup for per-test state.

Can one test override the default? Yes. Use [Setup] or [Teardown] inside a test to override the suite-wide default for that one test.


Next: tags in Robot Framework, or revisit user keywords and resource files.

Share:
Roy de Kleijn

Test Automation Expert

With over 15 years of experience in software testing and test automation, Roy helps teams improve their testing processes.

Get Robot Framework certified

Go from the basics to exam-ready at your own pace with the online RFCP course.