英文:
Playwright beforeAll *after* a fixture
问题
我有一个名为login
的装置,我希望在存储库中的每个测试开始时运行它。然后,我想要在describe
块中的一组测试之前/之后运行一个beforeAll
和afterAll
脚本(提供然后删除数据)。然而,beforeAll
在login
装置之前运行。
我是不是从错误的角度来解决这个问题?
英文:
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 '],
},
},
},
],
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论