Rayrun
← Back to Discord Forum

Is there an option that the Playwright test runner skips the afterEach hook?

alex_komanovposted in #help-playwright
Open in Discord

Hi there! In case of the failed assertion or due to the timeout of one of the functions - is it possible to get a case when a runner will not execute an afterEach hook?

Basically to be more specific - in case of failed assertion, and in case we need to do something inside our application as a part of the afterEach hook - will the failed assetion cloase the browser? Or in this case we will be able to execute the expected actions as part of the hook and then the browser will be closed?

This thread is trying to answer question "In case of the failed assertion or due to the timeout of one of the functions - is it possible to get a case when a runner will not execute an afterEach hook?"

2 replies

Hi, if you want to have different behavior in your afterEach you can use https://playwright.dev/docs/api/class-testinfo#test-info-status

And to have multiple cases you could inspect the test error using https://playwright.dev/docs/api/class-testinfo#test-info-errors

alex_komanov

Thanks - but does it mean that in any case, the afterEach hook will be triggered?

TwitterGitHubLinkedIn
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.