mcpField
T
testcafe-skill

testcafe-skill

github.com/lambdatest测试与质量384205 次安装2 周前更新
代码仓库

关于 testcafe-skill

为使用 TestCafe 自动化浏览器测试提供参考,面向 JavaScript 测试编写者,涵盖选择器、页面模型、浏览器运行、截图和 TestMu AI 云端执行。

主要功能

  1. 01TestCafe 测试模式
  2. 02选择器与页面模型
  3. 03浏览器及无头运行命令
  4. 04多浏览器测试执行
  5. 05截图与窗口控制
  6. 06TestMu AI 云端配置

适用场景

  1. 01使用 JavaScript 编写浏览器测试
  2. 02在多个浏览器中运行测试
  3. 03截取截图以辅助调试
  4. 04在 TestMu AI 云端执行测试

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/lambdatest/agent-skills --skill testcafe-skill

安装后在 Claude Code 中输入/testcafe-skill确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

reference/
advanced-patterns.md
cloud-integration.md
playbook.md

详细介绍

TestCafe 自动化技能

核心模式

基础测试
import { Selector } from 'testcafe';

fixture('Login').page('https://example.com/login');

test('Login with valid credentials', async t => {
    await t
        .typeText('#username', '[email protected]')
        .typeText('#password', 'password123')
        .click('button[type="submit"]')
        .expect(Selector('.dashboard').exists).ok();
});
选择器
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');
页面模型
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

有关完整的云端设置,请参阅 reference/cloud-integration.md;有关功能,请参阅 shared/testmu-cloud-reference.md。

export LT_USERNAME=your_username
export LT_ACCESS_KEY=your_key
npx testcafe "lambdatest:Chrome@latest:Windows 11" tests/
反模式
不佳做法推荐做法原因
await t.wait(5000)设置超时的智能断言任意延迟
深层 CSS 选择器Selector().withText()脆弱
不截取错误截图失败时调用 t.takeScreenshot()缺少调试信息

快速参考

任务命令
运行全部测试npx testcafe chrome tests/
无头运行npx testcafe chrome:headless tests/
运行指定测试npx testcafe chrome tests/login.js
多个浏览器npx testcafe chrome,firefox tests/
实时模式npx testcafe chrome tests/ --live
截图await t.takeScreenshot()
调整大小await t.resizeWindow(1280, 720)

深入模式

有关高级模式、调试指南、CI/CD 集成和最佳实践, 请参阅 reference/playbook.md。

评论

支持 Markdown