Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping on a protractor test with parameters

I have a set of smokescreen tests that are all pretty much identical. I would like to put them into a loop and loop at an array of parameters. However, the tests are running asynchronously and so the loop completes before the tests are run. This results in the test being run 8 times on the 8th parameter instead of once for each parameter.

describe('Admin Console Campaigns', function() {
    var ptor;
    var adminUrl;
    var testParams = [
        {title: 'Dashboard', urlSuffix: '/communic8' },
        {title: 'Campaign Report', urlSuffix: '/Reports/Campaign' },
        {title: 'Partner Campaign Usage', urlSuffix: '/Reporting/PartnerCampaignUsage' },
        {title: 'Campaign Template Usage', urlSuffix: '/Reporting/CampaignTemplateUsage' },
        {title: 'Email Usage Report', urlSuffix: '/Reports/EmailUsage' },
        {title: 'Campaign Templates', urlSuffix: '/CampaignTemplates' },
        {title: 'Campaign Template Groups', urlSuffix: '/CampaignTemplateGroups' },
        {title: 'New Template', urlSuffix: '/CampaignTemplates/Add' }
    ];

    beforeEach(function() {
        ptor = protractor.getInstance();
        ptor.ignoreSynchronization = true;
        var testParams = smokescreenTestConfig.adminCampaigns;
        adminUrl = ptor.params.http + ptor.params.client + ptor.params.staging + ptor.params.sharedvue + ptor.params.admin;
    });

    afterEach(function(){

    });

    for(var i=0; i < testParams.length; i++){
        var testParam = testParams[i];

        it('should have a ' + testParam.title + ' tab', function() {
            testUrl = adminUrl + testParam.urlSuffix;
            basicTestFunctions.pageExists(testUrl, ptor, browser, testParam.title);
        }, 60000);
    };
});

Does anyone have an idea of how to force the loop to wait on the tests?

like image 505
Robert McCraw Avatar asked Feb 07 '14 17:02

Robert McCraw


People also ask

How do you speed up a protractor test?

To do this is quite simple in protractor. Adding the shardTestFiles and maxInstences to your capabilities config should allow you to (in this case) run at most two test in parrallel. Increase the maxInstences to increase the number of tests run. Note : be careful not to set the number too high.

How do you fail a test case in a 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.


1 Answers

Ok figured this one out a while ago, sorry I forgot I had posted here. We basically created a configuration array in another file, (though this is not necessary, just makes the code easier to read) and then pulled that array into a var right above the test we wanted to repeat. Then we surrounded the test in a function inside of a loop and passed the lines from our array in with each loop.

var testParams = testConfig.testArray;

for (var i = 0; i < testParams.length; i++) {

  (function (testSpec) {
    it('write your test here', function () {
      //test code here
    });
  })(testParams[i]);

};

The key here is that "testParams[i]" at the end of the function passing in the iteration of the loop. This forces synchronous execution.

If you want to get really crazy we also ended up writing a batch file that runs this smokescreen about 50 times consecutively across all of our clients. We smokescreen our entire platform in about 10 minutes.

like image 128
Robert McCraw Avatar answered Oct 03 '22 05:10

Robert McCraw