量角器和 Cucumber.js:使用 mocha 的 promises 时,期望无法按预期工作
Protractor and Cucumber.js: expectations doesn't works as expected using promises with mocha
我一直在尝试使用量角器和黄瓜测试我的 angular 应用程序,但是当我使用 mocha 来创建期望时,当期望为假时,错误规范不会显示在控制台中。
路线http://localhost:9000/#/form29/form29'
的相关HTML
...
<h4 class="title">
The title
</h4>
...
我的步骤文件是:
//form29_steps.js
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised'),
assert;
chai.use(chaiAsPromised);
expect = chai.expect;
module.exports = function () {
this.Given(/^I am in the form 29 page$/, function (done) {
browser.get('http://localhost:9000/#/form29/form29');
done();
});
this.Then(/^should be the title "(.*)"/,function(title, done){
var el = element(by.css('.title'));
el.getText().then(function(text){
//a false expect
expect(title).to.eq('Aaaaa');
done();
});
});
};
当 expect 有效时没问题,但是当 expect 失败时没有 expect failed 错误并显示以下内容:
[16:14:08] E/launcher - "process.on('uncaughtException'" error, see launcher
[16:14:08] E/launcher - Process exited with error code 199
当我尝试相同但不使用 promised 时效果很好
this.Then(/^should be the title "(.*)"/,function(title, done){
var el = element(by.css('.title'));
expect(title).to.eq('A');
done();
});
我得到了我想要的错误:
Message:
AssertionError: expected 'Formulario 29' to equal 'A'
at World.<anonymous> (/protractor/test/e2e/features/step_definitions/form29_steps.js:18:20)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
为什么会这样?
[16:14:08] E/launcher - "process.on('uncaughtException'" error, see launcher
[16:14:08] E/launcher - Process exited with error code 199
以上错误可能是由多种原因引起的,主要与承诺有关。但它应该抛出正确的信息。这里已经提供了解决方法 https://github.com/angular/protractor/issues/3384 来捕获确切的错误消息。
您可以更改量角器依赖项中的 launcher.ts
文件,如上述论坛中所述,以捕获错误以便调试您的问题。
我一直在尝试使用量角器和黄瓜测试我的 angular 应用程序,但是当我使用 mocha 来创建期望时,当期望为假时,错误规范不会显示在控制台中。
路线http://localhost:9000/#/form29/form29'
的相关HTML...
<h4 class="title">
The title
</h4>
...
我的步骤文件是:
//form29_steps.js
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised'),
assert;
chai.use(chaiAsPromised);
expect = chai.expect;
module.exports = function () {
this.Given(/^I am in the form 29 page$/, function (done) {
browser.get('http://localhost:9000/#/form29/form29');
done();
});
this.Then(/^should be the title "(.*)"/,function(title, done){
var el = element(by.css('.title'));
el.getText().then(function(text){
//a false expect
expect(title).to.eq('Aaaaa');
done();
});
});
};
当 expect 有效时没问题,但是当 expect 失败时没有 expect failed 错误并显示以下内容:
[16:14:08] E/launcher - "process.on('uncaughtException'" error, see launcher
[16:14:08] E/launcher - Process exited with error code 199
当我尝试相同但不使用 promised 时效果很好
this.Then(/^should be the title "(.*)"/,function(title, done){
var el = element(by.css('.title'));
expect(title).to.eq('A');
done();
});
我得到了我想要的错误:
Message:
AssertionError: expected 'Formulario 29' to equal 'A'
at World.<anonymous> (/protractor/test/e2e/features/step_definitions/form29_steps.js:18:20)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
为什么会这样?
[16:14:08] E/launcher - "process.on('uncaughtException'" error, see launcher
[16:14:08] E/launcher - Process exited with error code 199
以上错误可能是由多种原因引起的,主要与承诺有关。但它应该抛出正确的信息。这里已经提供了解决方法 https://github.com/angular/protractor/issues/3384 来捕获确切的错误消息。
您可以更改量角器依赖项中的 launcher.ts
文件,如上述论坛中所述,以捕获错误以便调试您的问题。