2

I using console.log to write some elaborated msg about the current task/expect to be performed by protractor, but I found on console those messages are appearing before the actual task is performed in browser. Doing like this -

it('should validate all labels', function() {
    ....
    element.sendKey('name');
    console.log('name entered to user input');
    ...
});

Console log message is appearing before even the page is loaded in browser. So how to fix it?

giri-sh
  • 6,934
  • 2
  • 25
  • 50
coure2011
  • 40,286
  • 83
  • 216
  • 349

2 Answers2

3

That's because Protractor tries to run whatever it can, as it works on async principal. If you want to console.log something after the spec finishes then try to wait until the previous step's promise is resolved in the spec. Here's how -

it('should validate all labels', function() {
    ....
    element.sendKeys('name').then(function(){
        console.log('name entered to user input');
    });
    ...
});

Above code console logs your statement after sending data to the element. More on Protractor promises. Hope this helps.

Community
  • 1
  • 1
giri-sh
  • 6,934
  • 2
  • 25
  • 50
0

I agree with Girish's answer, but if you really want to log something independently of other promises, you could do something "hacky" like this:

driver.executeScript(function rf(a){return a;}, msg).then(function(s) {
    console.log(s);
});
GeoPro44
  • 41
  • 3