I have a suite which includes multiple specs. Each spec uses code on some libraries that return a rejected promise upon failure.
I can easily catch those rejected promises inside my spec. What I'm wondering about is that if I can make Protractor exit the whole suite inside that catch function, because the next specs inside the same suite are dependent on the success of the previous specs.
Pretend I have a suite called testEverything which has these specs openApp,signIn,checkUser,logout. If openApp fails, all next specs will fail due to dependency.
Consider this code for openApp:
var myLib = require('./myLib.js');
describe('App', function() {
  it('should get opened', function(done) {
    myLib.openApp()
    .then(function() {
      console.log('Successfully opened app');
    })
    .catch(function(error) {
      console.log('Failed opening app');
      if ( error.critical ) {
        // Prevent next specs from running or simply quit test
      }
    })
    .finally(function() {
      done();
    });
  });
});
How would I exit the whole test?
There is a module for npm called protractor-fail-fast.  Install the module npm install protractor-fail-fast.  Here's an example from their site where you would place this code into your conf file:
var failFast = require('protractor-fail-fast');
exports.config = {
  plugins: [{
    package: 'protractor-fail-fast'
  }],
  onPrepare: function() {
    jasmine.getEnv().addReporter(failFast.init());
  },
  afterLaunch: function() {
    failFast.clean(); // Cleans up the "fail file" (see below) 
  }  
}
Their url is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With