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

Playwright全局Teardown项目提前执行问题求助

Playwright全局Teardown提前执行问题

严格按照Playwright文档配置全局setup和teardown项目后,teardown项目始终在实际测试前执行。我尝试给测试项目额外添加"teardown"键,问题依旧。

我使用npx playwright init生成playwright.config.ts,添加了如下配置:

projects: [
  {
    name: 'setup',
    testMatch: /global\.setup\.ts/,
    teardown: 'teardown',
  },  
  {
    name: 'teardown',
    testMatch: /global\.teardown\.ts/,
  },
  { 
    name: 'chromium',
    use: { ...devices['Desktop Chrome'] },
    dependencies: ['setup'],
  },

  {
    name: 'firefox',
    use: { ...devices['Desktop Firefox'] },
    dependencies: ['setup'],
  },    
]

tests/global.setup.ts内容为:

console.log("H E L L O !")

global.teardown.ts内容为输出"BYE"。

运行测试时,teardown在setup后立即执行,早于实际测试:

$ npx playwright test --project=firefox
H E L L O !
B Y E

Running 2 tests using 2 workers
  2 passed (5.3s)

移除依赖后,setup和teardown都不会运行,符合预期。想问下有没有人按照文档示例成功让teardown在测试后执行?

内容的提问来源于stack exchange,提问作者Yves Dorfsman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 19:42:33