Playwright 仅从指定文件夹运行测试并忽略所有其他测试

Fid*_*eak 1 reactjs playwright

给出以下目录结构...

- /src/__mocks__
  - X.spec.tsx <-- mock test
  - Y.spec.tsx <-- mock test
  - Z.spec.tsx <-- mock test
- /src/e2e_tests <-------------- only run the tests inside this directory
  - X.spec.tsx <-- end-to-end test
  - Y.spec.tsx <-- end-to-end test
  - Z.spec.tsx <-- end-to-end test
- /src/components
  - A.tsx
  - A.spec.tsx <-- unit test
  - B.tsx
  - B.spec.tsx <-- unit test
  - C.tsx
  - C.spec.tsx <-- unit test
- /src/views
  - X.tsx
  - X.spec.tsx <-- unit test
  - Y.tsx
  - Y.spec.tsx <-- unit test
  - Z.tsx
  - Z.spec.tsx <-- unit test
- /src
  - App.tsx
  - index.tsx
- jest.config.ts
- playwright.config.ts
- package.json
- tsconfig.json
- tsconfig.spec.json
- ect...
Run Code Online (Sandbox Code Playgroud)

我已经尝试过以下操作:How do you specify a test folder/path with Playwright? 但是,这也将尝试运行该文件夹之外的所有测试。

我尝试阅读此处的文档: https: //playwright.dev/docs/test-configuration并尝试了以下组合:

  • 测试目录
  • 测试忽略
  • 测试匹配

但无法仅e2e_tests运行目录测试而忽略所有其他测试。

Ala*_*Das 6

一种方法是在现有的剧作家配置文件中创建一个项目,然后添加其中testDir,例如:

projects: [
  {
    name: 'chromium',
    use: {...devices['Desktop Chrome']},
  },
  {
    name: 'firefox',
    use: {...devices['Desktop Firefox']},
  },
  {
    name: 'webkit',
    use: {...devices['Desktop Safari']},
  },
  {
    name: 'e2e_tests',
    testDir: './src/e2e_tests',
    testMatch: /.*.spec.tsx/,
  },
]
Run Code Online (Sandbox Code Playgroud)

然后运行您的测试,例如:

npx playwright test --project=e2e_tests
Run Code Online (Sandbox Code Playgroud)