我正在尝试使用 Electron 和 Spectron 进行测试。
我想在我的正文中写入 contentEditable,然后检查我的测试中的文本是否匹配。到目前为止,我已经成功地为标题编写了一个测试,但我无法找到解决这个问题的方法。
索引.html;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body id = "test" contentEditable = true>
</body>
</html>
featureTest.js 包括标题的通过测试,以及我在底部想要的测试尝试。
const electron = require("electron");
var expect = require("chai").expect;
var Application = require("spectron").Application;
var assert = require("assert");
describe("application launch", function() {
this.timeout(10000);
beforeEach(function() {
this.app = new Application({
path: `${__dirname}/../node_modules/.bin/electron`,
args: ["main.js"]
});
return this.app.start();
});
afterEach(function() {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
});
it("title says Hello", function() {
return this.app.client
.waitUntilWindowLoaded()
.getTitle()
.then(text => expect(text).to.eq("Hello"));
});
it("inputs and then finds the text on the page", function() {
return this.app.client
.waitUntilWindowLoaded()
.elementIdText("test")
.keys("Hello World!")
.then(text => expect(text).to.eq("Hello World!"));
});
});
主.js;
const {app, BrowserWindow, Menu} = require('electron')
const path = require('path')
const url = require('url')
const fs = require("fs")
let mainWindow;
app.on('ready', function () {
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
// Open the DevTools.
// mainWindow.webContents.openDevTools()
mainWindow.on('closed', () => {
app.quit();
})
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
if(process.platform == 'darwin'){
mainMenuTemplate.unshift({});
}
});
包.JSON
"devDependencies": {
"chai": "^4.1.2",
"electron": "^1.7.8",
"mocha": "^4.0.1",
"spectron": "^3.7.2"
}