how to write dependent test cases in protractor/jasmine?

I am using protractor and jasmine as a unit testing tool for my project. I want to write dependent test cases for eg. If test case 1 fails do not execute test case 2 instead jump on test case 3 directly. Is it possible in protractor ? If yes then how ?

 conf.js

    suites: {
            network: 'consumerIndex.js',
            platform: 'adminIndex.js'

    }

adminIndex.js

    describe('Protractor Demo CTL App', function() {

            require('./adminPage.js');
            require('./addSeatPage.js');
            require('./groupusers.js');
            require('./invoiceSettings.js');

    }); 

addSeatPage.js

    it('case 1 ', function() {
            browser.driver.sleep(10000);    
            addSeat.productLink;
            expect(browser.getLocationAbsUrl()).toMatch("/seatSummarydsds");    
    });
    it('case 2 ', function() {

            browser.driver.sleep(10000);    
            element(by.css('[ng-click="goToBuyProducts()"]')).click();
            expect(browser.getLocationAbsUrl()).toMatch("/addSeat");

    });

    it('case 3', function() {
            browser.driver.sleep(10000);    
            addSeat.addToCart(browser.params.testData.datetimeTxt);
            expect(element(by.css('.errLabel')).isDisplayed()).toBe(true);
    });

I want to jump to case 3 if case 1 fails. Also is there any solution for jumping to next spec file i.e. groupusers.js directly if any of the case in addSeatPage.js fails ?

Upvotes: 0

Views: 1754

Answers (1)

SaWo
SaWo

Reputation: 1615

I believe dependent test cases should stay within one it() { ...} block. It is a bad smell if your test cases depend on each other. It is one of the first rules of software testing that you should Always Write Isolated Test Cases.

Upvotes: 2

Related Questions