我正在测试使用这些技术的 Electron 应用程序,即 Spectron,Chai,chai,正如所 promise 的,我想将测试用例编写在单独的文件中,但所有测试用例都放在一个文件中。
这是我尝试过的
describe("Login", function () {
this.timeout(10000);
//Case 1: wait for Electron window to open
it('open window', function () {
return app.client.waitUntilWindowLoaded().getWindowCount().should.eventually.equal(1);
});
//Case 2: Initial Login - Empty username & Password
it("Click on Login Without any Data", function () {
//Wait for window to load
return app.client.waitUntilWindowLoaded()
.setValue(usernametxt, "")
.setValue(passwordtxt, "")
.click(submitbtn)
.getText('.notification-content')
.should.eventually.equal("Please fill both username and password");
});
});
我只是想将案例1和案例2写入测试初始化文件中的单独文件中。
最佳答案
只需创建两个规范文件,将测试分开即可:
spec1.js
spec2.js
创建一个包含以下内容的.js文件(test.js):
require('spec1')
require('spec2')
在package.json中,请在mocha test命令中引用test.js:
"scripts": {
"test": "mocha test/test.js"
}
考虑到您有一个测试文件夹。
关于javascript - Electron ,Spectron : how to write test cases in seperate javascript file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50014468/