How to stop protractor from running further testcases on failure?

我只是一个虾纸丫 提交于 2019-12-18 01:57:23

问题


Is there a way of quitting test suite and stop executing further test cases, if a test case fails in protractor?


回答1:


In case of jasmine testing framework, you are not the first asking about it.

There are relevant open discussions/issues on exiting after a first failure, --fail-fast option:

  • Bail on first failure
  • --fail-fast option?
  • Please add --fail-fast support

Long story short, this is an open issue and some day jasmine would have the functionality built-in. Currently, use a third-party jasmine-bail-fast module.

Aside from that, there is a handy realtimeFailure jasmine setting. If you set it to true it would not fail the whole test run, but it would show errors in a real time - immediately after happening - this can possibly cover your use case. Set it in jasmineNodeOpts:

exports.config = {
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',

    ...

    jasmineNodeOpts: {
        realtimeFailure: true
    }
}



回答2:


Here is my solution to skip tests on first fail with Jasmine 2 and Protractor. Hope it helps.

exports.config = {
    onPrepare: function () {
        //skip tests after first fail
        var specs = [];
        var orgSpecFilter = jasmine.getEnv().specFilter;
        jasmine.getEnv().specFilter = function (spec) {
            specs.push(spec);
            return orgSpecFilter(spec);
        };
        jasmine.getEnv().addReporter(new function () {
            this.specDone = function (result) {
                if (result.failedExpectations.length > 0) {
                    specs.forEach(function (spec) {
                        spec.disable()
                    });
                }
            };
        });
    }
};



回答3:


jasmine-bail-fast didn't work in my case. Not sure if it was because of some conflicts with my other report plugins.

In case anyone is having the same problem. You can try protractor-fast-fail

exports.config = {
  plugins: [{
    package: 'protractor-fail-fast'
  }],

  onPrepare: function() {
    jasmine.getEnv().addReporter(failFast.init());
  },

  afterLaunch: function() {
    failFast.clean(); 
  }  
}

Worked perfectly well for me.




回答4:


you don't need all those third party plugins. Use native process.exit().

Code example:

it("test", function()
{
   ...
   if(isExit)
   {
      browser.driver.close().then(function()
      {
         process.exit(1);
      });
   }
});

profit.



来源:https://stackoverflow.com/questions/28893436/how-to-stop-protractor-from-running-further-testcases-on-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!