Introduction
Before and after hooks help run setup and cleanup steps automatically in tests. They make tests easier and cleaner by avoiding repeated code.
You want to open a website before each test starts.
You need to reset data after a test finishes.
You want to log in once before running several tests.
You want to clear cookies or local storage after tests.
You want to prepare test data before running tests.