protractor icon indicating copy to clipboard operation
protractor copied to clipboard

How to make onPrepare wait beforeLaunch to finish

Open helenGreene opened this issue 11 years ago • 4 comments

Hi, I use protractor to test big client application, before the tests run I use REST API to configure the server. I would like to use beforeLaunch for server configuration and some parameters initialization (that I need both for client and server) and then make some preparations on the client in onPrepare. The problem is it seems like onPrepare doesn't wait for the beforeLaunch to finish (in onPrepare I can't access parameters initialized in beforeLaunch). How can I make it wait? Thank you

helenGreene avatar Apr 07 '15 20:04 helenGreene

Have beforeLaunch return a promise when you are done with your setup. onPrepare will not start until it is resolved.

Example:

 beforeLaunch: function() {
    var q = require('q');
    var deferred = q.defer();       

    // Do some things
    doAllTheThings().then(function(){
        deferred.resolve();
    });


    return deferred.promise;
},

brocsk avatar Apr 07 '15 20:04 brocsk

Closing as an answered question.

juliemr avatar Apr 08 '15 20:04 juliemr

Thank you, but it still doesn't work :( Also, several things I do in beforeLaunch() are not async.

helenGreene avatar Apr 13 '15 10:04 helenGreene

It sounds like you probably have some sort of variable scoping issues then.

juliemr avatar Apr 13 '15 18:04 juliemr