用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/materialofair/oh-my-codex --skill electron-driver命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | electron-driver |
| description | E2E Testing & Automation for Electron Apps (Playwright) |
| model | sonnet |
| version | 0.1.0 |
| source | fork |
| checksum | e44a4288375c0d42cb602a811d60898e45f8ec8dc3eac176f5890244b7f1afc6 |
| updated_at | 2026-02-06T07:19:11.000Z |
| layer | domain |
The standard tool for End-to-End (E2E) Verification of Electron Applications.
Use this skill when you need to:
Supports two robust modes: Launch (Clean E2E Test) and Attach (Live Debugging).
--remote-debugging-port).e2e and tddelectron-driver is the Electron-specific execution backend in the testing stack:
$tdd validates core logic and IPC units first.$e2e defines end-user journey scenarios.$electron-driver executes those scenarios against real Electron runtime windows/processes.Use this skill when $e2e detects Electron context or when desktop-runtime debugging is required.
npm install playwright-core (locally preferred) or npm install -g playwright-core.node_modules/.bin/electron or the packaged app).--remote-debugging-port=<port>.| Mode | Use Case | Pros | Cons |
|---|---|---|---|
| Launch | Automated tests, reproducible tasks | Clean env, no port conflicts, auto-close | Slower start, loses current app state |
| Attach | Debugging current session, "Drive my app" | Preserves state, instant feedback | Complex setup (ports), fragile |
Create a script that launches the app.
File: test-driver.cjs (Use .cjs to avoid ESM/CJS issues)
const { _electron: electron } = require('playwright-core');
(async () => {
// Launch the app
// args: pointing to main.js or the packaged app executable
const app = await electron.launch({
args: ['.'], // Or path to executable
env: { ...process.env, NODE_ENV: 'development' }
});
try {
// Smart Window Find (ignoring DevTools)
const page = await app.firstWindow();
if (page.url().startsWith('devtools://')) {
// Loop to find real window if first one is devtools
// (Logic typically handled by waiting for first non-devtools window)
}
console.log(`Title: ${await page.title()}`);
// --- ACTION LOGIC ---
// Modern Locator API
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByText('Welcome')).toBeVisible(); // requires @playwright/test runner or stand-alone expect
page.().();
} (err) {
.(err);
} {
app.();
}
})();
Pre-check: Ensure app is running with --remote-debugging-port=9222 (or check console for actual port).
File: attach-driver.cjs
const { chromium } = require('playwright-core');
(async () => {
try {
// Connect to CDP
const browser = await chromium.connectOverCDP('http://localhost:9222');
// Find the right page (Filter out DevTools)
const context = browser.contexts()[0];
const pages = context.pages();
const page = pages.find(p => !p.url().startsWith('devtools://'));
if (!page) throw new Error('No valid app window found');
// --- ACTION LOGIC ---
await page.locator('#submit-btn').click();
// --------------------
await browser.close(); // Disconnects (does not kill app)
} catch (e) {
console.error(e);
}
})();
page.getByRole('button', { name: 'Save' })page.getByText('Hello World')page.getByPlaceholder('Email')page.locator('.css-class')await locator.click()await locator.fill('text')await page.waitForSelector(...) (Old)await locator.waitFor() (Explicit)await locator.click() (Auto-waits)SyntaxError: Cannot use import statement... -> Save file as .mjs or change project type. Recommendation: Always save temp scripts as .cjs and use require.基于 SOC 职业分类