I would like to suggest a small improvement to other answers.
short answer : I like to use browser.sleep(0).then(..);
where I need to push something to protractor's flow.
it is generic and easy to move around.
tl;dr
so using the above, you can easily add a function on browser (or ptor) something like:
browser.log = function( logger, level, msg ){
browser.sleep(0).then(function(){ logger[level](msg); });
}
or something a bit more sophisticated with apply
- but that depends on your logger.
you can obviously enhance that a bit to have logger like api
var logger = browser.getLogger('name');
should be implemented like (lets assume log4js)
browser.getLogger = function( name ){
var logger = require('log4js').getLogger(name);
function logMe( level ) {
return function(msg ){
browser.sleep(0).then(function(){ logger[level](msg); });
}
}
return { info : logMe('info'), ... }
}
basically, the sky is the limit.
I am sure there's a way to make my code a lot shorter, the point is using the sleep
method as basis.