如何让Playwright的global teardown全局清理功能正常运行?
Playwright全局清理(global teardown)无法运行的问题
我一直在尝试为Playwright设置全局清理,但始终无法使其运行。已按照官方文档示例操作,但无效。我没有设置全局初始化,不过认为这不会影响全局清理的运行。配置中仅使用globalTeardown选项指向目标文件,以下是该文件的示例代码:
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); } }
cleanUpFunc是Page对象或CustomPage对象上的方法,受保密协议(NDA)限制无法提供具体代码,如有需要可尝试给出示例。
感谢您的帮助!
内容的提问来源于stack exchange,提问作者Lee McCready
相关产品推荐
相关产品推荐

