测试咖啡馆技能(testcafe-skill)
2026-10-22查看 7复制 0
使用 JavaScript 或 TypeScript 生成 TestCafe 自动化测试。
📘如何使用这个技能
- 1复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
- 2打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
- 3粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
- 4直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景
💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。
SKILL.md2691 chars
---
name: testcafe-skill
description: >
Generates TestCafe automation tests in JavaScript or TypeScript. Supports local
and TestMu AI cloud. Triggers on: "TestCafe", "test cafe", "fixture/test".
languages:
- JavaScript
- TypeScript
category: e2e-testing
license: MIT
metadata:
author: TestMu AI
version: "1.0"
---
# TestCafe Automation Skill
## Core Patterns
### Basic Test
```javascript
import { Selector } from 'testcafe';
fixture('Login').page('https://example.com/login');
test('Login with valid credentials', async t => {
await t
.typeText('#username', 'user@test.com')
.typeText('#password', 'password123')
.click('button[type="submit"]')
.expect(Selector('.dashboard').exists).ok();
});
```
### Selectors
```javascript
const submitBtn = Selector('button').withText('Submit');
const listItems = Selector('.item').count;
const nthItem = Selector('.item').nth(2);
const filtered = Selector('.item').withAttribute('data-status', 'active');
```
### Page Model
```javascript
import { Selector, t } from 'testcafe';
class LoginPage {
constructor() {
this.usernameInput = Selector('#username');
this.passwordInput = Selector('#password');
this.submitButton = Selector('button[type="submit"]');
}
async login(username, password) {
await t
.typeText(this.usernameInput, username)
.typeText(this.passwordInput, password)
.click(this.submitButton);
}
}
export default new LoginPage();
```
### TestMu AI Cloud
See [reference/cloud-integration.md](reference/cloud-integration.md) for full cloud setup and [shared/testmu-cloud-reference.md](../shared/testmu-cloud-reference.md) for capabilities.
```bash
export LT_USERNAME=your_username
export LT_ACCESS_KEY=your_key
npx testcafe "lambdatest:Chrome@latest:Windows 11" tests/
```
### Anti-Patterns
| Bad | Good | Why |
|-----|------|-----|
| `await t.wait(5000)` | Smart assertions with timeout | Arbitrary delays |
| Deep CSS selectors | `Selector().withText()` | Fragile |
| No error screenshots | `t.takeScreenshot()` on failure | Missing debug info |
## Quick Reference
| Task | Command |
|------|---------|
| Run all | `npx testcafe chrome tests/` |
| Run headless | `npx testcafe chrome:headless tests/` |
| Run specific | `npx testcafe chrome tests/login.js` |
| Multiple browsers | `npx testcafe chrome,firefox tests/` |
| Live mode | `npx testcafe chrome tests/ --live` |
| Screenshot | `await t.takeScreenshot()` |
| Resize | `await t.resizeWindow(1280, 720)` |
## Deep Patterns
For advanced patterns, debugging guides, CI/CD integration, and best practices,
see `reference/playbook.md`.