Seeking a solution to execute shared code across tests in various spec files in Playwright using TypeScript. Specifically, I need to upload test results based on the testInfo
. While I know that fixtures can achieve this, it's not the most efficient option. With fixtures, I have to specify them for each test, even if I don't need to reference them directly in my tests. This increases the risk of forgetting to include the fixture in new tests or accidentally removing it during cleanup.
I've noticed that importing files containing beforeAll
or afterAll
will work as intended. However, attempting the same with beforeEach
or afterEach
only triggers the code once, rather than before and after each test individually.
Is there a method to replicate the functionality of beforeEach
or afterEach
in multiple spec files without adding unnecessary code to each test?