Protractor times out waiting for sync with page when using $resource(使用 $resource 时量角器超时等待与页面同步)
问题描述
我正在用一个小型 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 时量角器超时等待与页面同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 $resource 时量角器超时等待与页面同步


- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01