How can I use BrowserMob Proxy with Protractor?
You need to denodeify callbacks, i.e. turn them into Promises so Protractor will wait for them.
Alternative 1: Using already included protractor.promise
//...
onPrepare: function() {
var deferred = protractor.promise.defer();
proxy.doHAR('http://yahoo.com', function(err, data) {
if (err) {
deferred.reject('ERROR: ' + err);
} else {
deferred.fulfill(data);
}
});
return deferred.promise;
}
Alternative 2: Using Q library
var Q = require('q');
//...
onPrepare: function() {
var proxy_doHAR = Q.nfbind(proxy.doHAR);
return proxy_doHAR('http://yahoo.com');
}
More info here and here.