impregnable fiend impregnable fiend - 5 months ago 13
AngularJS Question

How to write beforeSomeTests in Protractor?

Learning JS, wondering is it possible in Protractor to do something like

before Test1,3,5,7,9,11 etc(function(){
browser.get('http://192.168.1.117:7777/#/route1');
});


and

before Test2,4,6,8,10 etc(function(){
browser.get('http://192.168.1.117:7777/#/route2');
});


Or the only way to do before is

beforeEach(function(){
browser.get('http://192.168.1.117:7777/#/route');
});


Don't wanna write
browser.get
every time, but can't use
beforeEach
cause it's 2 routes, not 1. Excuse me, if my question is ordinary, thanks in advance :)

Answer

What i have understood from above question is that you have two different baseUrls and need to use one for a group of test cases and other for remaining test cases.

If I'm right, then answer is "You DON'T have such option". You can do either of following alternative solutions:

  1. Divide the test cases into Groups(say describe block here). The test cases which needs to run one first baseUrl, keep them all in one describe block

describe('group of test cases which uses route1 url',function(){

    beforEach(function(){
          browser.get("http://baseUrl1/route1");   
          }) or
    beforeAll()//you can use one of them
    it('test case1',function(){});
    it('test case2',function(){});
    it('test case3',function(){});

});

describe('group of test cases which uses route2 url',function(){

    beforEach(function(){           
         browser.get("http://baseUrl2/route2")   
    }) or
    beforeAll()//you can use one of them
    it('test case1',function(){});
    it('test case2',function(){});
    it('test case3',function(){});

});

  1. Try with "Using Multiple Browsers in the Same Test" http://www.protractortest.org/#/browser-setup
Comments