Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop protractor from running further testcases on failure?

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

like image 608
Aman Gupta Avatar asked Mar 06 '15 06:03

Aman Gupta


People also ask

How do you stop an execution in protractor?

Use native process. exit() . Code example: it("test", function() { ... if(isExit) { browser.

How to fail test case in protractor?

async WaitToBeClickable(element){ try{ for(var i = 0; i <= 3000; i++){ var wait = await browser. wait(this. EC. elementToBeClickable(element), i); if(wait == true){ break; }else{ //this is where I want to fail } } }catch(err){ //this is where I want to fail await console.


3 Answers

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
    }
}
like image 80
alecxe Avatar answered Oct 21 '22 13:10

alecxe


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()
                    });
                }
            };
        });
    }
};
like image 11
Daniel Schwab Avatar answered Oct 21 '22 11:10

Daniel Schwab


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

import failFast from 'protractor-fail-fast';

exports.config = {
  // if import statement doesn't work, use this instead of import for older versions of node
  // plugins: [{
  //  package: 'protractor-fail-fast'
  // }],

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

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

Worked perfectly well for me.

EDIT: added import statement in code snippet to reflect readme of projactor-fast-fail

like image 9
Linh Pham Avatar answered Oct 21 '22 13:10

Linh Pham