I have been struggling to implement a global teardown for Playwright, but I am unable to get it to execute. Despite following the guidelines provided in the documentation, the teardown function refuses to work. Although I do not have a setup command running, I fail to see how it would impact the execution of the teardown. In my configuration, I simply utilize the globalTeardown
option to specify the file that needs to be executed. Below is an example snippet from the file being referenced:
async function globalTeardown(_config: FullConfig) {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = new CustomPage(await context.newPage());
try{
await context.tracing.start({ screenshots: true, snapshots: true });
cleanUpFunc(page);
await browser.close();
} catch (error) {
context.tracing.stop({
path: './test-results/teardown-trace.zip',
});
await browser.close();
throw("Global setup error:\n" + error);
}
}
In the cleanUpFunc
function, there will be various operations performed on the Page
or CustomPage
objects, which I am unable to provide specific examples for.
Due to NDA constraints, I cannot share actual code snippets, but I am willing to offer guidance through generic illustrations if necessary.
Appreciate your assistance!