我正在用一个小型 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模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XMLHttpRequest 的 getResponseHeader() 的限制?Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)