testcafe-skill について
TestCafe によるブラウザーテスト自動化のリファレンスです。JavaScript のテスト作成者向けに、セレクター、ページモデル、ブラウザー実行、スクリーンショット、TestMu AI クラウド実行を扱います。
主な機能
- 01TestCafe のテストパターン
- 02セレクターとページモデル
- 03ブラウザー・ヘッドレス実行コマンド
- 04複数ブラウザーでのテスト実行
- 05スクリーンショットとウィンドウ制御
- 06TestMu AI クラウドの設定
活用シーン
- 01JavaScript でのブラウザーテスト作成
- 02複数ブラウザーでのテスト実行
- 03デバッグ用スクリーンショットの取得
- 04TestMu AI クラウドでのテスト実行
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ lambdatest/ agent-skills --skill testcafe-skillインストール後、Claude Code で/testcafe-skillを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
reference/advanced-patterns.mdcloud-integration.mdplaybook.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 対応