問題描述
我正在用一個小型 AngularJS 應用程序測試 Protractor.
I'm testing Protractor with a small AngularJS app.
這是測試:
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 運行此測試會導致以下錯誤:
Running this test using Protractor results in the following error:
Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds
但是,如果在控制器中我更改此行:
However, if in the controller I change this line:
$scope.drafts = Draft.query();
到這里:
$scope.drafts = [];
測試按預期失敗,但更重要的是:它不會超時.
The test fails as expected, but more importantly: it does not time out.
啟用 query() 后,無論是在瀏覽器中手動運行應用程序,還是查看 Protractor 打開的瀏覽器窗口時,API 返回的數據都會由中繼器正確顯示.
With query() enabled, both when running the app manually in a browser and when looking at the browser window opened by Protractor, the data returned by the API is correctly displayed by a repeater.
為什么服務與 API 通信時 Protractor 無法與頁面同步?
Why is Protractor not able to synchronize with the page when the service is communicating with the API?
AngularJS 是 v1.2.0-rc3.量角器是 v0.12.0.
AngularJS is v1.2.0-rc3. Protractor is v0.12.0.
推薦答案
這是一個已知問題,但是有一個臨時的解決方法.設置 ptor.ignoreSynchronization = true
.
This is a known issue, but there is a temporary workaround. Set ptor.ignoreSynchronization = true
.
例如:
describe('Testing Protractor', function() {
var draftList;
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;
});
it('should count the number of drafts', function() {
ptor.get('#/');
draftList = element.all(by.repeater('newsletter in drafts'));
expect(draftList.count()).toEqual(2);
});
});
這篇關于使用 $resource 時量角器超時等待與頁面同步的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!