Protractor 量角器-当断言失败时,测试执行突然停止

Protractor 量角器-当断言失败时,测试执行突然停止,protractor,chai,e2e-testing,cucumberjs,Protractor,Chai,E2e Testing,Cucumberjs,黄瓜步骤定义 Then(/^Submit Button is disabled$/, function (done) { element(by.buttonText('Search')).isEnabled().then(function (result) { expect(result).to.equal(false); done(); }); }) exports.config = { // seleniumAddress: 'http

黄瓜步骤定义

Then(/^Submit Button is disabled$/, function (done) {
    element(by.buttonText('Search')).isEnabled().then(function (result) {

        expect(result).to.equal(false);
        done();
    });
})
exports.config = {
  // seleniumAddress: 'http://127.0.0.1:9001/',
  resultJsonOutputFile: "./e2e_report/report.json",
  getPageTimeout: 60000,
  allScriptsTimeout: 500000,
  framework: 'custom',
  // path relative to the current config file
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  capabilities: {
    'browserName': 'chrome',
    chromeOptions: {
      args: [
        '--start-maximized'
      ]
    }
  },
  // Spec patterns are relative to this directory.
  specs: [
    './features/*.feature'
  ],
  baseURL: 'https://angularjs.org/',
  cucumberOpts: {
    require: ["./features/globals.js", './features/steps/*.js'],
    tags: [],
    format: 'pretty',
    profile: false,
    'no-source': true,
    "compiler": [] //,
    //format:"json:./e2e_report/report.json"
  }
};
控制台错误:

[12:17:13]E/launcher-预期false等于true [12:17:13]E/launcher-AssertionError:预期false等于true 位于D:\Mercurial\PromotionFinder\PromotionFinder\PromotionFinder.Web\features\steps\cucumber.js:178:31 在elementArrayFinder.then(C:\Users\abhishes\AppData\Roaming\npm\node\u modules\Gragrator\lib\element.ts:840:22) 在ManagedPromise.invokeCallback(C:\Users\abhishes\AppData\Roaming\npm\node\u modules\dragrator\node\u modules\selenium webdriver\lib\promise.js:1366:14) 在TaskQueue.execute(C:\Users\abhishes\AppData\Roaming\npm\node\u modules\dragrator\node\u modules\selenium webdriver\lib\promise.js:2970:14) 在TaskQueue.executeNext(C:\Users\abhishes\AppData\Roaming\npm\node\u modules\dragrator\node\u modules\selenium webdriver\lib\promise.js:2953:27) 异步运行时(C:\Users\abhishes\AppData\Roaming\npm\node\u modules\dragrator\node\u modules\selenium webdriver\lib\promise.js:2813:27) 在C:\Users\abhishes\AppData\Roaming\npm\node\u modules\dragrator\node\u modules\selenium webdriver\lib\promise.js:676:7 在进程中。_tick回调(内部/process/next_tick.js:103:7) [12:17:13]E/launcher-进程退出,错误代码199

量角器配置

Then(/^Submit Button is disabled$/, function (done) {
    element(by.buttonText('Search')).isEnabled().then(function (result) {

        expect(result).to.equal(false);
        done();
    });
})
exports.config = {
  // seleniumAddress: 'http://127.0.0.1:9001/',
  resultJsonOutputFile: "./e2e_report/report.json",
  getPageTimeout: 60000,
  allScriptsTimeout: 500000,
  framework: 'custom',
  // path relative to the current config file
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  capabilities: {
    'browserName': 'chrome',
    chromeOptions: {
      args: [
        '--start-maximized'
      ]
    }
  },
  // Spec patterns are relative to this directory.
  specs: [
    './features/*.feature'
  ],
  baseURL: 'https://angularjs.org/',
  cucumberOpts: {
    require: ["./features/globals.js", './features/steps/*.js'],
    tags: [],
    format: 'pretty',
    profile: false,
    'no-source': true,
    "compiler": [] //,
    //format:"json:./e2e_report/report.json"
  }
};
每当断言失败时,测试执行就会突然停止,并且不会生成测试报告

我正在使用 量角器版本-5、cucumberjs版本2.0.0和chai&chai,如断言所承诺的那样

我需要以下信息:

1个场景(1个失败) 5个步骤(1个失败,3个跳过,1个通过)


创建result.json,以便在teamcity中查看结果。

我还没有使用CucumberJS 2.0.0,因为它是RC版本,我在互联网上看到了一些问题。2.1.0是一个稳定的版本,所以可能可以解决这个问题

当我看你的代码时,我认为这应该可以做到

//带有回调
然后(/^Submit按钮被禁用,$/,功能(完成){
var searchButton=element(by.buttonText('Search'));
返回expect(searchButton.isEnabled()).to.finally.equal(false)和.notify(done);
});
//承诺
然后(/^Submit按钮被禁用,$/,函数(){
var searchButton=element(by.buttonText('Search'));
返回expect(searchButton.isEnabled()).to.finally.equal(false);

});您需要捕获异常。 有两种方法可以做到这一点。 在返回时捕获异常

Then(/^Submit Button is disabled$/, function (done) {
    element(by.buttonText('Search')).isEnabled().then(function (result) {

        expect(result).to.equal(false);
        done();
    }).catch(function(err){
            return;
    });
});
另一种方法是在函数定义中添加回调作为参数

Then(/^Submit Button is disabled$/, function (done, callback) {
    element(by.buttonText('Search')).isEnabled().then(function (result) {

        expect(result).to.equal(false);
        done();
    }).catch(function(reason) {
            callback(reason);
    });
});