Vla*_*ler 4 javascript mocha.js end-to-end chai nightwatch.js
我试图用nightwatch.js和mocha runner定义一些测试.我想测试我的javascript库如何在不同的浏览器中工作.
我的代码非常简单,看起来就像那样
const expect = require('chai').expect;
describe('InfinitiSpec', function() {
beforeEach((client, done) => {
client.url(`file://${__dirname}/../../dist/index.html`);
done();
});
after((client, done) => {
client.end(() => done());
});
it('should be five', (client) => {
client.execute(function() {
// test javascript here
}, [], () => {
expect(2 + 2).to.equal(5)
});
});
});
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,守夜人没有将done回调传递给测试,因此即使单个测试断言失败,测试本身仍然看起来像是成功的.
vladmiller:infiniti-tracking-evolution vladmiller$ nightwatch
InfinitiSpec
? AssertionError: expected 4 to equal 5
at Object.<anonymous> (/Users/vladmiller/Projects/xxx/xxx/test/browser/infiniti.spec.js:18:24)
at HttpRequest.<anonymous> (/usr/local/lib/node_modules/nightwatch/lib/index.js:322:20)
at emitTwo (events.js:87:13)
at HttpRequest.emit (events.js:172:7)
at HttpRequest.<anonymous> (/usr/local/lib/node_modules/nightwatch/lib/index.js:351:15)
at emitThree (events.js:97:13)
at HttpRequest.emit (events.js:175:7)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/nightwatch/lib/http/request.js:155:16)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
? should be five (3322ms)
1 passing (3s)
Run Code Online (Sandbox Code Playgroud)
如何使用nightwatch + mocha + chai测试异步javascript?也许人们可以推荐更好的堆栈来测试硒中的JS?谢谢
Nightwatch使用不支持异步测试的mocha修补版本.解决方案是使用标准的mocha,但相关文档(http://nightwatchjs.org/guide#using-the-standard-mocha)不完整,并且在该上下文中访问页面对象时会遇到麻烦.
花了一个小时试图用标准摩卡设置Nightwatch后,我决定回到普通的Selenium Webdriver.老实说,我并不后悔.
如果您想了解如何使用Selenium进行类似Nightwatch的Page对象的建议,请查看http://marmelab.com/blog/2016/04/19/e2e-testing-with-node-and-es6.html
| 归档时间: |
|
| 查看次数: |
2093 次 |
| 最近记录: |