2015-10-20 14 views
1

我的角度控制器看起來是這樣的:如何在量角器中記錄httprequest的結果?

myApp.controller('Ctrl1', ['$scope','$http', function ($scope,$http) { 
    console.log('hello'); 
    $scope.testing = 'hello man'; 
$http.get("https://api.github.com/repos/vmg/redcarpet/issues").success(function (data) { 
     // success 
     console.log('success'); 


    }).error(function (error) { 
     // error 
     console.log(JSON.stringify("Failed to get t&c: " + error)); 
    }); 

}]); 

我的端對端測試是這樣的:

afterEach(function() { 
       browser.manage().logs().get('browser').then(
        function (browserLog) { 
         console.log('\n log: ' + require('util').inspect(browserLog)); 
        }); 
      }); 


    it('should show success in console', function() { 
       browser.get('http://localhost:63342/basic_protractor_osx/index.html'); 

      }); 

當我運行量角器日誌數組是空的,而當我打開德的index.html與控制器在控制檯中顯示'成功'。我如何用量角器測試控制器,以便測試成功?

回答

0

你必須定義你想從瀏覽器記錄的capatibilities在conf.js

capabilities: { 
    'browserName': 'chrome', 
    'chromeOptions': { 
     args: ['--test-type'] 
    }, 
    'loggingPrefs': { 
     browser: 'ALL' 
    } 
}, 

然後從瀏覽器中得到日誌像你一樣。

+0

仍然不會從http調用中返回console.log? –

+0

@bierhier你的'require'('util').inspect(browserLog)'做了什麼?只要打印它'console.log(browserLog);' – vrachlin

相關問題