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 时量角器超时等待与页面同步
基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01