如何在量角器中记录httprequest的结果?

时间:2015-10-20 11:03:16

标签: angularjs protractor

我的角度控制器看起来像这样:

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));
    });

}]);

我的e2e测试看起来像这样:

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');

            });

当我运行量角器时,日志数组为空,而当我用控制器打开de index.html时,它在控制台中显示“成功”。如何用量角器测试控制器,以便测试是否成功?

1 个答案:

答案 0 :(得分:0)

您必须定义您希望从conf.js

中的功能中获取浏览器中的日志
capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
        args: ['--test-type']
    },
    'loggingPrefs': {
        browser: 'ALL'
    }
},

然后像你一样从浏览器中获取日志。