暂无描述

playwright.config.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // @ts-check
  2. import { defineConfig, devices } from '@playwright/test';
  3. import fs from 'node:fs';
  4. /**
  5. * Read environment variables from file.
  6. * https://github.com/motdotla/dotenv
  7. */
  8. // require('dotenv').config({ path: path.resolve(__dirname, '.env') });
  9. const BROWSERS = ['Chrome', 'Firefox'];
  10. const files = fs.readdirSync('tests', { withFileTypes: true });
  11. const users = files.filter(file => file.isDirectory()).map(file => file.name);
  12. // setup project
  13. let projects = [{
  14. name: 'setup',
  15. testMatch: 'auth.setup.js',
  16. }];
  17. for (const browser of BROWSERS) {
  18. for (const user of users) {
  19. projects.push({
  20. name: `${browser}:${user}`,
  21. use: {
  22. ...devices[`Desktop ${browser}`],
  23. storageState: `playwright/.auth/${user}.json`,
  24. },
  25. testDir: `./tests/${user}`,
  26. dependencies: ['setup'],
  27. })
  28. }
  29. }
  30. /**
  31. * @see https://playwright.dev/docs/test-configuration
  32. */
  33. module.exports = defineConfig({
  34. testDir: './tests',
  35. /* Run tests in files in parallel */
  36. fullyParallel: true,
  37. /* Fail the build on CI if you accidentally left test.only in the source code. */
  38. forbidOnly: !!process.env.CI,
  39. /* Retry on CI only */
  40. retries: process.env.CI ? 2 : 0,
  41. /* Opt out of parallel tests on CI. */
  42. workers: process.env.CI ? 1 : undefined,
  43. /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  44. reporter: 'html',
  45. /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  46. use: {
  47. /* Base URL to use in actions like `await page.goto('/')`. */
  48. baseURL: 'https://localhost',
  49. /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
  50. trace: 'on-first-retry',
  51. ignoreHTTPSErrors: true,
  52. },
  53. /* Configure projects for major browsers */
  54. projects: projects,
  55. /* Run your local dev server before starting the tests */
  56. // webServer: {
  57. // command: 'npm run start',
  58. // url: 'http://127.0.0.1:3000',
  59. // reuseExistingServer: !process.env.CI,
  60. // },
  61. });