Javascript 电子应用程序在spectron测试中打开多个窗口或进程
我的electron应用程序按预期工作,但当我运行spectron测试时,它会不断打开新窗口,测试打开的窗口数 电子版-v8.0.2,“光谱”:“^10.0.1”。我不知道如何检查spectron的确切版本。 我只是在运行一个小演示,下面我将给出代码片段 注意:我正在运行spectron测试,指向由electron packager生成的.exe文件。 有人知道问题是什么吗?如果可能的话,怎么解决 main.jsJavascript 电子应用程序在spectron测试中打开多个窗口或进程,javascript,node.js,electron,Javascript,Node.js,Electron,我的electron应用程序按预期工作,但当我运行spectron测试时,它会不断打开新窗口,测试打开的窗口数 电子版-v8.0.2,“光谱”:“^10.0.1”。我不知道如何检查spectron的确切版本。 我只是在运行一个小演示,下面我将给出代码片段 注意:我正在运行spectron测试,指向由electron packager生成的.exe文件。 有人知道问题是什么吗?如果可能的话,怎么解决 main.js const { app, BrowserWindow } = require('e
const { app, BrowserWindow } = require('electron')
function createWindow () {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
const assert = require('assert');
const path = require('path');
const Application = require('spectron').Application;
const electronPath = require('electron');
const app = new Application({
path: 'C:/demoElectronApp/winx64/demoelectronapp-win32-x64/demoelectronapp.exe',
});
describe('client_settings_app', function () {
this.timeout(10000);
beforeEach(() => {
return app.start();
});
it('shows only one initial window', async () => {
const count = await app.client.getWindowCount();
return assert.equal(count, 1);
});
})
index.js
const { app, BrowserWindow } = require('electron')
function createWindow () {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
const assert = require('assert');
const path = require('path');
const Application = require('spectron').Application;
const electronPath = require('electron');
const app = new Application({
path: 'C:/demoElectronApp/winx64/demoelectronapp-win32-x64/demoelectronapp.exe',
});
describe('client_settings_app', function () {
this.timeout(10000);
beforeEach(() => {
return app.start();
});
it('shows only one initial window', async () => {
const count = await app.client.getWindowCount();
return assert.equal(count, 1);
});
})
package.json
{
"name": "demoelectronapp",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"electronpackage": "electron-packager . --out winx64"
},
"author": "",
"license": "ISC",
"dependencies": {
"path": "^0.12.7"
},
"devDependencies": {
"electron": "^8.2.2",
"electron-packager": "^14.2.1",
"assert": "^2.0.0",
"mocha": "^7.1.1",
"spectron": "^10.0.1"
}
}
我遇到了类似的问题,并更改了我正在使用的软件包的版本。 此页面具有版本映射:
这似乎不是你的问题,因为它可能会帮助其他人。npm ls--depth=0demoelectronapp@1.0.0C:\demoCLS\demoElectronApp+-assert@2.0.0 +-- electron@8.2.2+--电子-packager@14.2.1 +-- mocha@7.1.1 +-- path@0.12.7 `-- spectron@10.0.1Above是否安装了npm软件包可能对OP没有帮助,但它解决了多个窗口问题为我使用Spectron时出现问题。不知道为什么会有反对票,答案甚至说它不会解决OP的问题。