I am using protractor recently, and want to understand the best way of dealing with console.logs. For promise involved browser activity like click(),enter() which returns promise i am consoling in promise resolve in success block it works fine. But in other types of actions where i am required to use expect, expect itself resolves the promise returned by the condition and if i do try {} catch{} still that doesnt sound to be right way of console.log for that action. So what is happening is when i am doing console.log after expect action those gets logged prior to promise involved actions.
So how can i trigger the consoles which doesn't involve promise? Also as these gets logged prior to promise logs, does that mean the actions such as expect also occur prior to click() action?
Sample code for click() is as below //below the log happens after resolve.
this.click = function () {
element(by.id("")).click().then(
function success() {
console.log("activity details");
},
function error(reason) {
console.error(reason);
console.log(data);
throw reason;
});
Code for non-promise returning functions such as below- //comparetext is after click() and logs prior to click(). I do understand promise are async so this console prints prior to click success, but is there no any way i can log success log after click log itself?
this.compareText=function(){
expect(element(by.id("something")).getText()).toBe("matching text");
console.log("success");
}
I had tried this also few days back,
browser.manage().logs().get('browser').then(function(browserLog) {
logger.info('log: ' + require('util').inspect(browserLog));
});
but they were logging the logs which are not at all are errors and was stopping the execution.