You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 18:02:38