在Protractor中的httpBackend API模拟模块中打印请求

lou*_*ros 7 angularjs protractor httpbackend ngmocke2e e2e-testing

我在量角器中使用角度服务$ httpBackend对模拟的API运行我的e2e测试.

我已经有了selenium浏览器的调试日志:

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
          );
        }
      };
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

我想在我的httpBackend模块中打印每个请求的URL标题(例如,对于用户资源):

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

但是在httpBackend模块内的任何地方都没有记录任何内容.当我在我的应用程序中使用它时它工作正常,但是当我在量角器中使用它时它没有.

有没有办法在任何地方打印?即使在输出文本文件中?

Del*_*kin 11

console.log()WebDriver 忽略语句.您可以使用console.info(),console.warn()console.error()作为描述在这里.