javascriptpromiseprotractorjasmine-reporters

how to return multiple reporters in protractor afterlaunch function that are wrapped up in promises?


I have the following reporters

 afterLaunch: function (exitCode) {

    return new Promise(function (resolve) {
        reporter1.afterLaunch(resolve.bind(this, exitCode));
    });

    return new Promise(function (resolve) {
        reporter2.afterLaunch(resolve.bind(this, exitCode));
    });
}

Each of the above reporters have their own afterlaunch that would be expected to execute once the afterlaunch in the ptor.conf file is executed.

But apparently because of the return new Promise, the first report gets returned from there itself and the execution stops there.

How would it possible to return both the reports at the same time?


Solution

  • You need the Promise.all() (or the protractor.promise.all() if you are operating the webdriver promises):

    var promise1 = new Promise(function (resolve) {
        reporter1.afterLaunch(resolve.bind(this, exitCode));
    });
    
    var promise2 = new Promise(function (resolve) {
        reporter2.afterLaunch(resolve.bind(this, exitCode));
    });
    
    return Promise.all([promise1, promise2]);