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

Protractor - Tests execution stops abruptly when assertion is failed

黄瓜步骤定义

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

        expect(result).to.equal(false);
        done();
    });
})

控制台错误:

[12:17:13] E/launcher - expected false to equal true [12:17:13] E/launcher - AssertionError: expected false to equal true at D:\Mercurial\PromotionFinder\PromotionFinder\PromotionFinder.Web\features\steps\cucumber.js:178:31 at elementArrayFinder_.then (C:\Users\abhishes\AppData\Roaming\npm\node_modules\protractor\lib\element.ts:840:22) at ManagedPromise.invokeCallback_ (C:\Users\abhishes\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1366:14) at TaskQueue.execute_ (C:\Users\abhishes\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2970:14) at TaskQueue.executeNext_ (C:\Users\abhishes\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2953:27) at asyncRun (C:\Users\abhishes\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2813:27) at C:\Users\abhishes\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:676:7 at process._tickCallback (internal/process/next_tick.js:103:7) [12:17:13] E/launcher - Process exited with error code 199

量角器配置

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"
  }
};

只要断言失败,测试执行就会突然停止,并且不会生成测试报告。

我正在使用 Protractor 版本 - 5,cucumberjs 版本 2.0.0 和 chai & chai-as-promised for assertion

我需要如下信息:

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

和 result.json 将被创建,以便我可以在 teamcity 中看到结果。

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

当我查看您的代码时,我认为这应该可以解决问题。

// With callbacks
Then(/^Submit Button is disabled$/, function(done) {
  var searchButton = element(by.buttonText('Search'));
  return expect(searchButton.isEnabled()).to.eventually.equal(false).and.notify(done);
});

// With Promises
Then(/^Submit Button is disabled$/, function() {
  var searchButton = element(by.buttonText('Search'));
  return expect(searchButton.isEnabled()).to.eventually.equal(false);
});

希望对您有所帮助

您需要捕获异常。 有两种方法可以做到这一点。 在 return...

捕获异常
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);
    });
});