1.1. should-add-single-todo【免费下载链接】playwrightPlaywright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.项目地址: https://gitcode.com/GitHub_Trending/pl/playwrightFile:tests/adding-todos/should-add-single-todo.spec.tsSteps:Navigate to the TodoMVC applicationexpect: The application loads successfullyexpect: The input field What needs to be done? is visibleType Buy groceries into the input fieldexpect: The text appears in the input fieldPress Enter to submit the todoexpect: The new todo Buy groceries appears in the todo listexpect: The input field is clearedexpect: The todo counter shows 1 item left### 5.2 种子文件与 fixture页面初始状态 种子文件 [seed.spec.ts](https://link.gitcode.com/i/b1b15c03869ac4fc607eeb99ec7298a2) 是一个近乎空白的测试 ts import { test, expect } from ./fixtures; test(seed, async ({ page }) { // This test tells agents how to start recording the test // so that the page was already configured. });其注释直接点明了用途告诉代理如何开始录制测试以便页面已经完成配置。真正的初始化逻辑在 fixtures.ts 中——它扩展了playwright/test的pagefixture在每次测试开始前执行page.goto(https://demo.playwright.dev/todomvc)。因此generator_setup_page运行种子测试后页面即停留在 TodoMVC demo 首页代理从输入框可见这一步开始实时执行无需重复导航。5.3 生成产物输出对照 should-add-single-todo.spec.ts可以看到代理规范在真实产物中的体现// seed: tests/seed.spec.ts import { test, expect } from ../fixtures; test.describe(Adding Todos, () { test(should add single todo, async ({ page }) { // Step 1: Navigate to the TodoMVC application // Expect: The application loads successfully, The input field What needs to be done? is visible await expect(page.getByRole(textbox, { name: What needs to be done? })).toBeVisible(); // Step 2: Type Buy groceries into the input field await page.getByRole(textbox, { name: What needs to be done? }).fill(Buy groceries); // Expect: The text appears in the input field await expect(page.getByRole(textbox, { name: What needs to be done? })).toHaveValue(Buy groceries); // Step 3: Press Enter to submit the todo await page.keyboard.press(Enter); // Expect: The new todo Buy groceries appears in the todo list await expect(page.getByText(Buy groceries)).toBeVisible(); // Expect: The input field is cleared await expect(page.getByRole(textbox, { name: What needs to be done? })).toHaveValue(); // Expect: The todo counter shows 1 item left await expect(page.getByText(1 item left)).toBeVisible(); }); });逐条验证规范落实情况单测试单文件整个文件只有一个test()文件名 fs-friendly计划场景名should-add-single-todo直接作为文件名describe 与顶层计划条目一致计划### 1. Adding Todos→test.describe(Adding Todos)test 标题与场景名一致test(should add single todo)步骤注释每个步骤前有// Step N: ...注释预期写成// Expect: ...且一个步骤的多条预期合并为一条注释未重复最佳实践体现选择器全部来自实时执行时拿到的可访问性信息——getByRole(textbox, { name: What needs to be done? })这类基于 ARIA role 的稳定选择器而非脆弱的 CSS 路径。tests/目录下按功能子目录adding-todos/、completing-todos/、editing-todos/、deleting-todos/、filtering-todos/、todo-creation/组织了十余个此类生成文件与计划中的**File:**字段一一对应印证了generator_write_test中按 project 的 testDir 校验并自动建目录写入的行为。5.4 运行环境配置playwright.config.ts 声明了testDir: ./tests即generator_write_test的合法写入边界、timeout: 15_000、expect.timeout: 5_000、CI 下的retries: 2与workers: 1以及仅启用chromium项目devices[Desktop Chrome]firefox/webkit 项目被注释保留。package.json 提供四个脚本scripts: { test: playwright test, ctest: playwright test --projectchromium, ftest: playwright test --projectfirefox, wtest: playwright test --projectwebkit }【免费下载链接】playwrightPlaywright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.项目地址: https://gitcode.com/GitHub_Trending/pl/playwright创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考