Playwright 在夹具之前 *之后* 执行

huangapple go评论90阅读模式
英文:

Playwright beforeAll *after* a fixture

问题

我有一个名为login的装置,我希望在存储库中的每个测试开始时运行它。然后,我想要在describe块中的一组测试之前/之后运行一个beforeAllafterAll脚本(提供然后删除数据)。然而,beforeAlllogin装置之前运行。

我是不是从错误的角度来解决这个问题?

英文:

I have a login fixture that I want to run at the beginning of every test in the repository. I then want to do a beforeAll and afterAll script (supply and then delete data) to run before/after a group of tests in a describe block. However, the beforeAll runs before the login fixture.

Am I approaching this from the wrong angle?

答案1

得分: 1

我有一个登录的固定装置,我想在存储库中的每个测试开始之前运行它。然而,在登录固定装置之前运行 beforeAll。

检查 globalSetup 和 Auth

英文:

> I have a login fixture that I want to run at the beginning of every test in the repository. However, the beforeAll runs before the login fixture.

Check globalSetup and Auth

答案2

得分: 0

根据您的项目需求,您可以通过在您的playwright.config.ts文件中使用设置和拆卸项目依赖来添加您的数据。

因此,您的配置可能包含类似于以下内容 - 我的Chromium项目依赖于'setup'。 因此,'setup'将首先运行并设置我的数据,然后运行'chromium'测试,最后运行'teardown'测试以清除您的数据。

projects: [
    {
      name: 'setup',
      testDir: 'tests/setup/',
      teardown: 'teardown',
    },
	{
      name: 'teardown',
      testMatch: /tests/teardown/,
    },
    {
      name: 'chromium',
      dependencies: ['setup'],
      use: {
        browserName: 'chromium',
        headless: false,
        screenshot: 'only-on-failure',
        trace: 'on',
        launchOptions: {
          args: ['--disable-extensions '],
        },
      },
    },
  ],
英文:

Depending on your project needs, you could add your data by using setup and teardown project dependencies in your playwright.config.ts.

So your config could include something like this - my chromium project has a dependency on 'setup'. So 'setup' will be run first and has tests to setup my data, then 'chromium' tests run, and then 'teardown' tests to nuke your data.

projects: [
    {
      name: 'setup',
      testDir: 'tests/setup/',
      teardown: 'teardown',
    },
	{
      name: 'teardown',
      testMatch: /tests/teardown/,
    },
    {
      name: 'chromium',
      dependencies: ['setup'],
      use: {
        browserName: 'chromium',
        headless: false,
        screenshot: 'only-on-failure',
        trace: 'on',
        launchOptions: {
          args: ['--disable-extensions '],
        },
      },
    },
  ],

huangapple
  • 本文由 发表于 2023年6月16日 01:45:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定