e2e
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesee2e: agentic end-to-end tests in TypeScript
e2e:TypeScript 中的 Agent 驱动端到端测试
e2e runs UI tests with agent goals and exact assertions. drives
one goal; , , and judge the
screen. , , , and make exact interactions and
checks. The replay cache reruns verified actions and checks their recorded end
state without a model call; agent judgments still run live. UI targets use
for browsers or for iOS simulators and
Android emulators. A test that takes only can check an API with
and (topic ). Model sign-in commands are in
setup.
agent.actagent.assertagent.waitForagent.extractscreenappbrowserexpect@e2e-dev/web@e2e-dev/mobileappfetchexpectwriting-teststs
// e2e.config.ts
import type { E2EConfig } from 'e2e';
import { web } from '@e2e-dev/web';
import { gateway } from 'ai';
export default {
targets: [
{
engine: web(),
app: {
url: 'http://127.0.0.1:3000',
command: { executable: 'pnpm', args: ['dev'], log: '.e2e/logs/app.log' },
},
},
],
// The model behind every agent.* step: an AI SDK instance; gateway() from 'ai' reads AI_GATEWAY_API_KEY or a Vercel OIDC token.
agents: {
default: {
model: gateway('openai/gpt-6-luna-fast'),
system: 'You are a thorough QA agent. Verify every outcome on screen.',
},
},
} satisfies E2EConfig;ts
// tests/billing.e2e.ts
import { test } from '@e2e-dev/web';
import { expect } from 'e2e';
test('a member upgrades to Pro', async ({ app, agent, screen, browser }) => {
await app.open('/settings/billing');
await agent.act('upgrade the workspace to the Pro plan');
await expect(screen.getByRole('status')).toContainText('Pro');
await expect(browser).toHaveURL('/settings/billing');
});e2e 使用 Agent 目标和精确断言来运行 UI 测试。 驱动单个目标;、 和 根据屏幕内容进行判断。、、 和 用于执行精确的交互与检查。replay cache 无需调用模型即可重放已验证的操作,并检查其记录的最终状态;Agent 判断仍会实时执行。UI target 使用 处理浏览器,或使用 处理 iOS 模拟器和 Android 模拟器。仅使用 的测试可以通过 和 检查 API(主题 )。模型登录命令见 setup。
agent.actagent.assertagent.waitForagent.extractscreenappbrowserexpect@e2e-dev/web@e2e-dev/mobileappfetchexpectwriting-teststs
// e2e.config.ts
import type { E2EConfig } from 'e2e';
import { web } from '@e2e-dev/web';
import { gateway } from 'ai';
export default {
targets: [
{
engine: web(),
app: {
url: 'http://127.0.0.1:3000',
command: { executable: 'pnpm', args: ['dev'], log: '.e2e/logs/app.log' },
},
},
],
// The model behind every agent.* step: an AI SDK instance; gateway() from 'ai' reads AI_GATEWAY_API_KEY or a Vercel OIDC token.
agents: {
default: {
model: gateway('openai/gpt-6-luna-fast'),
system: 'You are a thorough QA agent. Verify every outcome on screen.',
},
},
} satisfies E2EConfig;ts
// tests/billing.e2e.ts
import { test } from '@e2e-dev/web';
import { expect } from 'e2e';
test('a member upgrades to Pro', async ({ app, agent, screen, browser }) => {
await app.open('/settings/billing');
await agent.act('upgrade the workspace to the Pro plan');
await expect(screen.getByRole('status')).toContainText('Pro');
await expect(browser).toHaveURL('/settings/billing');
});Topics
主题
Read the topic for the job before writing code. The files sit next to this
one; the installed CLI prints the same text with
( alone prints this page). For anything the topics do not cover,
the full documentation ships in the directory of the installed
package ( in a single-package project); a link such as
is .
npx e2e guide <topic>e2e guidedocs/e2enode_modules/e2e/docs/reference/clidocs/reference/cli.mdx| Topic | File | Read it when |
|---|---|---|
| references/setup.md | Adding e2e to a project, writing |
| references/writing-tests.md | Writing or fixing tests: fixtures, locators, actions, matchers, sign-in sessions, the |
| references/agent.md | Adding |
| references/running.md | CLI flags, reporters, |
| references/explore.md | Exploring an app toward a goal without a test file: |
| references/debugging.md | A run failed: error codes and their fixes, |
| references/mcp.md | Driving the live app from a coding agent over MCP: |
| references/bug-bash.md | Asked to bug bash, QA, or hunt for bugs across an app or a branch: parallel |
编写代码前,先阅读与任务对应的主题。相关文件位于本文档旁;已安装的 CLI 可通过 打印相同文本(仅运行 会打印本页)。如果主题未涵盖某项内容,完整文档随已安装的 包一起提供,位于 目录(在单包项目中为 );例如 这样的链接对应 。
npx e2e guide <topic>e2e guidee2edocs/node_modules/e2e/docs/reference/clidocs/reference/cli.mdx| 主题 | 文件 | 何时阅读 |
|---|---|---|
| references/setup.md | 将 e2e 添加到项目、编写 |
| references/writing-tests.md | 编写或修复测试:fixtures、locators、actions、matchers、登录会话、 |
| references/agent.md | 添加 |
| references/running.md | 使用 CLI flags、reporters、 |
| references/explore.md | 无需测试文件、以目标为导向探索应用时:了解 |
| references/debugging.md | 运行失败时:了解错误代码及其修复方式、 |
| references/mcp.md | 通过 MCP 从 coding agent 驱动实时应用时:了解 |
| references/bug-bash.md | 被要求进行 bug bash、QA 或跨应用或分支排查缺陷时:并行执行 |
Workflow
工作流
- Look at what exists: or
e2e.config.ts, thee2e.config.mtsglob (defaulttests),tests/**/*.e2e.tsine2e. Nothing there: followpackage.json.setup - Learn the screens before writing a test: routes, labels, roles, button
text. Semantic locators need the accessible names the app renders, so read
the components, open the page with , or drive the live app over the registered
--headedserver (topice2e mcp):mcp,open_session, andobserveshow exact names and check a locator before you write it.locate - Write . Drive the flow with
tests/<feature>.e2e.ts, one goal per call, and pin each outcome right after withagent.actorexpect. Exact values go throughagent.assert: a sign-in form in a setup test, a field that must receive one specific string, a count that must be one number.screen - Run one file: . Agent steps need a model in the config and that provider's authentication (a saved subscription login, an API key); a local endpoint may need none. Tests without agent steps need no model.
npx e2e run tests/<feature>.e2e.ts - Read the failure: the reporter prints the error code, message, and a code
frame; has every step and artifact path. Fix the locator, the expectation, or the app. Never add a sleep.
.e2e/report.json
- 先查看现有内容:或
e2e.config.ts、e2e.config.mtsglob(默认值为tests)、tests/**/*.e2e.ts中的package.json。如果这些都不存在:请遵循e2e主题。setup - 编写测试前先了解界面:路由、标签、角色和按钮文本。语义 locator 需要应用渲染出的可访问名称,因此应阅读组件、使用 打开页面,或通过已注册的
--headedserver 驱动实时应用(主题e2e mcp):mcp、open_session和observe会显示确切名称,编写 locator 前应先检查它。locate - 编写 。使用
tests/<feature>.e2e.ts驱动流程,每次调用只处理一个目标,并紧接着使用agent.act或expect固定每个结果。精确值通过agent.assert处理:setup 测试中的登录表单、必须填入某个特定字符串的字段、必须等于某个数字的计数。screen - 运行单个文件:。Agent 步骤需要在配置中提供模型,并准备好相应提供方的认证信息(已保存的订阅登录或 API key);本地 endpoint 可能无需认证。不含 Agent 步骤的测试不需要模型。
npx e2e run tests/<feature>.e2e.ts - 读取失败信息:reporter 会打印错误代码、消息和代码帧;包含每个步骤及其 artifact 路径。修复 locator、expectation 或应用。绝不要添加 sleep。
.e2e/report.json
Rules
规则
- Run the CLI as (or
npx e2e ...).pnpm exec e2e ... - The config is with
export default { ... } satisfies E2EConfig.import type { E2EConfig } from 'e2e'is required; a UI target names an engine and declares the app beside it:targets. A tools-only target can omit the engine and set{ engine: web(), app: { url, command } }.platform - Import ,
test, the hooks,describe,expect, andcredentialsfromsecrets. A test that uses thee2efixture importsbrowser,test, and the hooks fromdescribe: the same runtime functions, typed with@e2e-dev/web.browser - Config and tests are ES modules whatever sets as
package.json.type - Locators resolve when used. Actions wait for readiness and retries assertions. Reads such as
expectfail at once on zero matches andtextContent()answers from the current screen; nothing waits for a value to change, so use a matcher when a value has to settle.count() - A locator that matches two nodes fails with ; narrow it (topic
LOCATOR_AMBIGUOUS).writing-tests - Secrets never appear in test code. Declare accounts under and every other sensitive value under
credentialsin the config; resolve withsecretsorcredentials.user(name).password(separate namespaces:secrets.get(name)never returns a password), and hand the opaquesecrets.getonly toSecretorfill()params.agent.act - Agent instructions: one goal per , the wording on screen, real values in params. Judge meaning, not phrasing:
act, not an exact sentence a model produced.toContain('Pro') - Check each agent goal's outcome. A passing with a recorded check can be cached and replayed without model calls (topic
act).agent - Shape the agent for this app: for vocabulary the screens use,
contextfor how it works, tools for a test API, named personas undersystem. When a step fails, tighten the goal first, then the context, then the agent.agents - is output (
.e2e/,report.json,artifacts/,cache/; the config'slogs/moves the report and artifacts, neveroutputor the app's log). Read it, never edit it.cache/
- 使用 (或
npx e2e ...)运行 CLI。pnpm exec e2e ... - 配置应采用 形式,并使用
export default { ... } satisfies E2EConfig。import type { E2EConfig } from 'e2e'为必填项;UI target 需要指定 engine,并在旁边声明 app:targets。仅工具 target 可以省略 engine 并设置{ engine: web(), app: { url, command } }。platform - 从 导入
e2e、test、hooks、describe、expect和credentials。使用secretsfixture 的测试需从browser导入@e2e-dev/web、test和 hooks:它们是相同的运行时函数,只是带有describe类型。browser - 无论 的
package.json设置为何,配置和测试都使用 ES modules。type - Locator 在使用时解析。操作会等待就绪状态,会重试断言。
expect等读取操作在零匹配时立即失败,textContent()则根据当前屏幕返回结果;不会自动等待值发生变化,因此当值需要稳定下来时应使用 matcher。count() - 匹配两个节点的 locator 会以 失败;应缩小匹配范围(主题
LOCATOR_AMBIGUOUS)。writing-tests - 密钥绝不能出现在测试代码中。在配置中将账户声明在 下,其他所有敏感值声明在
credentials下;通过secrets或credentials.user(name).password解析(两个命名空间彼此独立:secrets.get(name)永远不会返回密码),并且只能将不透明的secrets.get传给Secret或fill()的参数。agent.act - Agent 指令:每次 只设置一个目标,使用屏幕上的措辞,并在参数中填写真实值。判断语义而非表述:使用
act,不要要求模型生成完全一致的句子。toContain('Pro') - 检查每个 Agent 目标的结果。成功且结果检查已记录后,即可缓存并在无模型调用的情况下重放(主题
act)。agent - 针对此应用配置 Agent:使用 描述界面使用的词汇,使用
context描述工作方式,使用system提供测试 API,并在tools下定义具名 personas。步骤失败时,先收紧目标,再调整 context,最后调整 Agent。agents - 是输出目录(
.e2e/、report.json、artifacts/、cache/;配置中的logs/会移动报告和 artifacts,但不会移动output或应用日志)。只读取,不要编辑。cache/
Feedback
反馈
When e2e itself gets in your way, tell the e2e team: a command or API that
broke (), docs or this skill that misled you (), or a capability
you needed and did not find (). Send it once per problem, after you
worked around it or gave up, never for failures of the app under test.
bugdocsfeaturebash
npx e2e feedback --type bug -m "<one or two sentences>" \
--task "<what you were doing>" --expected "<...>" --actual "<error code and message>" \
--approach "<what you tried>" --command "<e2e command>" --agent "<agent / model>"Describe e2e's behavior only: never paste app content, page text, test files,
URLs of private apps, or credentials. Secret-named environment variables and
common token shapes are redacted, but do not rely on it. prints
what would be sent. Tell the user you sent it and give them the reference id
it prints.
--dry-run当 e2e 本身妨碍你工作时,请告知 e2e 团队:某个命令或 API 出现故障()、文档或此 skill 误导了你(),或者你所需的功能不存在()。每个问题只发送一次,并且应在你已经绕过问题或放弃之后发送;被测应用自身的失败绝不要发送。
bugdocsfeaturebash
npx e2e feedback --type bug -m "<one or two sentences>" \
--task "<what you were doing>" --expected "<...>" --actual "<error code and message>" \
--approach "<what you tried>" --command "<e2e command>" --agent "<agent / model>"仅描述 e2e 的行为:绝不粘贴应用内容、页面文本、测试文件、私有应用 URL 或凭据。以 secret 命名的环境变量和常见 token 形式会被脱敏,但不要依赖这一点。 会打印将要发送的内容。告知用户你已发送反馈,并提供它打印的 reference id。
--dry-run