我正在用一个小型 AngularJS 应用程序测试 Protractor。
这是测试:
describe('Testing Protractor', function() {
var draftList;
it('should count the number of drafts', function() {
browser.get('#/');
draftList = element.all(by.repeater('newsletter in drafts'));
expect(draftList.count()).toEqual(2);
});
});
控制器:
angular.module('myApp.controllers', []).
controller('DraftsCtrl', ['$scope', 'Draft', function($scope, Draft) {
$scope.drafts = Draft.query();
}])
草稿服务:
angular.module('myApp.services', ['ngResource']).
factory('Draft', ['$resource',
function($resource) {
return $resource('api/drafts/:id')
}])
使用 Protractor 运行此测试会导致以下错误:
Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds
但是,如果在控制器中我更改此行:
$scope.drafts = Draft.query();
对此:
$scope.drafts = [];
测试按预期失败,但更重要的是:它不会超时。
启用 query() 后,无论是在浏览器中手动运行应用程序,还是查看 Protractor 打开的浏览器窗口时,API 返回的数据都会由中继器正确显示。
为什么 Protractor 在服务与 API 通信时无法与页面同步?
AngularJS 是 v1.2.0-rc3。量角器是 v0.12.0。