name: spectron-test-setup description: 为遗留Electron应用设置Spectron(已弃用)测试 allowed-tools: Read, Write, Edit, Bash, Glob, Grep tags: [electron, testing, spectron, legacy, deprecated]
spectron-test-setup
为遗留Electron应用程序设置Spectron测试。注意:Spectron已弃用;新项目请使用Playwright。
能力
- 配置Spectron测试环境
- 生成测试结构
- 设置WebDriverIO集成
- 处理应用程序生命周期
- 创建页面对象
输入模式
{
"type": "object",
"properties": {
"projectPath": { "type": "string" },
"electronPath": { "type": "string" }
},
"required": ["projectPath"]
}
测试示例
const Application = require('spectron').Application;
const path = require('path');
describe('应用程序启动', function () {
beforeEach(function () {
this.app = new Application({
path: require('electron'),
args: [path.join(__dirname, '..')]
});
return this.app.start();
});
afterEach(function () {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
});
it('显示初始窗口', function () {
return this.app.client.getWindowCount().then(count => {
expect(count).toBe(1);
});
});
});
迁移说明
考虑迁移到 playwright-electron-config 以进行现代化的Electron测试。
相关技能
playwright-electron-configelectron-mock-factory