Only run tests if previous tests haven't failed

829 Views Asked by At

TL:DR; I have an list. You can: Add, Remove, Edit and Search/Filter items.

I want to run my tests only if the first test it('shall delete a new item', ..) was successful.

Is there a way I can do this?

2

There are 2 best solutions below

1
On

I am looking for a better way to do this, but this is a hacky way I would do it.

  1. Use afterEach to set a conditional
  2. Return from test if that conditional is false;

    var firstPassed = true;
    
    it ('first test', function() {
        ....
    });
    
    it('second test', function(){
        if (!firstPassed) return;
        ....
    });
    
    afterEach(function() {
        if(this.results_.description === 'first test'){
            if(this.results_.failedCount !== 0){
                firstPassed = false;
            }
        }
    }
    
0
On

You can tell protractor to "failfast". That is it should stop running subsequent tests as soon as one test fails. Not quite what you're asking for but technically accomplishes what you want in this case.

This is really a (missing) feature of the test runner (Jasmine, Jasmine2, etc), so the specific solution might be different. If you're using the default, Jasmine, see How to stop protractor from running further testcases on failure?