- 编剧版本:[v1.36]
- 操作系统:[全部、Windows 11、Ubuntu 20、macOS 13.2 等]
- 浏览器:[全部、Chromium、Firefox、WebKit]
- 其他信息:
- [ ] 我提供了准确的源代码,可以在本地重现该问题。看起来全局拆卸大约需要 30 秒,但测试执行需要 1 秒。我从 CLI 工具进行了简单的测试,并将项目添加到配置文件中。需要注意的重要事项:如果我执行 by testMatch =/.*.spec.ts/,则所有工作均按要求进行
链接到带有重现的 GitHub 存储库
[ https://github.com/your_profile/playwright_issue_title ]
或者
配置文件
// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';
/**
 * See https://playwright.dev/docs/test-configuration.
 */
const config: PlaywrightTestConfig = {
  projects: [
    {
      name: 'test',
      testMatch: '*tests/*.spec.ts',
    },
],
  testMatch: /.*.spec.ts/,
  /* Maximum time one test can run for. */
  timeout: 60 * 1000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 20000,
  },
  /* Run tests in files in parallel */
  fullyParallel: !!process.env.CI,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 0 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 5 : 1,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: [['list']],
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    channel: process.env.DOCKER ? 'chromium' : 'chrome',
    headless: !!process.env.CI,
    viewport: { width: 1280, height: 720 },
    ignoreHTTPSErrors: true,
    baseURL: 'https://playwright.dev/',
    /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
    actionTimeout: 30000,
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'retain-on-failure',
    video: 'retain-on-failure',
    screenshot: 'only-on-failure',
  },
  /* Folder for test artifacts such as screenshots, videos, traces, etc. */
  outputDir: 'test-results/',
};
export default config;
测试文件(独立)
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/Playwright/);
});
test('get started link', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  // Click the get started link.
  await page.getByRole('link', { name: 'Get started' }).click();
  // Expects the URL to contain intro.
  await expect(page).toHaveURL(/.*intro/);
});
脚步
- [运行测试] pnpm运行测试
- [...]
预期的
[描述预期行为]
实际的
[描述实际行为]