Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print request in httpBackend API mock module in Protractor

I run my e2e tests against a mocked API using angular service $httpBackend in protractor.

I already have the debug log of the selenium browser:

afterEach(function() {
  browser.manage().logs().get('browser').then(function(browserLog){
    if(browserLog.length) {
      for (var i = 0; i < browserLog.length; i++) {
        if( typeof browserLog[i] !== 'undefined') {
          console.log(
            JSON
            .parse(browserLog[i].message).message.parameters[0].value
          );
        }
      };
    }
  });
});

I'd like to print URL and headers of each request inside my httpBackend module (eg for users resourse) :

$httpBackend
  .whenGET(/^\/api\/users.*$/)
  .respond(function(method, url, data, headers) {
     var users = mockUserService.getData();
     console.log(url);
     console.log(headers);
     return [200, users, {}];
});

But nothing is logged anywhere inside the httpBackend module. It works fine when I use it in my app but not when I use it with protractor.

Is there any way to print it anywhere? Even in an output text file?

like image 373
louis amoros Avatar asked Apr 15 '15 19:04

louis amoros


1 Answers

console.log() statements are ignored by WebDriver. You can use console.info(), console.warn() or console.error() as described here.

like image 200
Delian Mitankin Avatar answered Oct 18 '22 16:10

Delian Mitankin