I'm looking for a way to run some common code across tests in multiple spec files in Playwright typescript. My particular case is wanting to upload test results based on testInfo
. I'm aware that fixtures can be used for this, but this is not ideal. With fixtures, I need to specify the fixture for every test, and in my case I don't need to reference the fixture within my tests. This makes it easy to not include the fixture on new tests, and accidentally remove it with lint clean up on existing tests.
I have seen that importing files that include beforeAll
or afterAll
will run that code as expected. But doing the same with beforeEach
or afterEach
only runs that code once, instead of once for each test.
Is there a way to get functionality like beforeEach
or afterEach
for multiple spec files without having to add superfluous code to each test?