← Back to Discord Forum

test.afterAll not working as expected?

From my understanding "test.afterAll()" should be executed after all "test" and execute only once? But i see that it gets executed in "After hook" after each test


This thread is trying to answer question "How can the issue of 'test.afterAll()' being executed multiple times be avoided?"

6 replies

once per worker, if you're running on several workers then it will be executed in each worker

if you're running on a single worker but test fails, then a new worker will be created which means afterAll will also run multiple times

how that can be avoided?

use global teardown perhaps

bit tricky, since some data created during test execution are needed for tear down

maybe you need to store the data created in some json file. I have to use that approach due to I need some accesibility errors I tried with soft assertions but is the same behavior this is my issue in github https://github.com/microsoft/playwright/issues/23586

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.