ignoreUncaughtExceptions:false

时间:2018-02-22 12:17:07

标签: cucumber angular5 e2e-testing cucumberjs

我们正在使用量角器 - 黄瓜 - 框架,并且对CucumberJs v4.0进行了最新更新,如果E2E功能在任何步骤失败,则json报告不会生成 - json文件保持为空。

仅当cucumberOpts参数ignoreUncaughtExceptions设置为false时才会发生这种情况。问题是如何在cucumberOpts: ignoreUncaughtExceptions: false时生成步骤失败的json报告。

AfterAfterAll挂钩无效

1 个答案:

答案 0 :(得分:0)

根据protractor-cucumber-framework readme,使用ignoreUncaughtExceptions: true是处理量角器未捕获异常的方法。

由于mentionned by darrinholst黄瓜会处理此错误here

      process.on('uncaughtException', (exc: (Error|string)) => {
       let e = (exc instanceof Error) ? exc : new Error(exc);
       if (config.ignoreUncaughtExceptions) {
        // This can be a sign of a bug in the test framework, that it may
        // not be handling WebDriver errors properly. However, we don't
        // want these errors to prevent running the tests.
        logger.warn('Ignoring uncaught error ' + exc);
        return;
       }...

另一种解决方案是返回承诺,让黄瓜处理错误,不再需要ignoreUncaughtExceptions: true

此代码:

Then(/^I can say Hello World$/, function(done: any) {
  this.page
    .sayHelloWorld()
    .then(done);
});

会这样写:

Then(/^I can say Hello World$/, function() {
  return this.page.sayHelloWorld();
});