问题描述:
我们最近在Protractor端到端测试中打开应用程序中的一个页面时遇到了这个臭名昭着的错误:
Failed: Timed out waiting for asynchronous Angular tasks to finish after 50 seconds. This may be because the current page is not an Angular application.
这发生在browser.get(“/ some / page /”);在我们的一个测试中打电话:
describe("Test", function () {
beforeEach(function () {
browser.get("/some/page/");
});
it("should test something", function () {
// ...
});
)};
并且,我们的案例有点奇怪的是,我们的Angular Web应用程序中的任何其他页面都没有抛出错误 – Protractor与Angular同步而没有任何问题. ng-app位置方面的所有页面都相同 – ng-app在root html标记上定义:
<html class="ng-scope" lang="en-us" ng-app="myApp" ng-strict-di="">
行为是一致的 – 每次我们使用browser.get()导航到此页面时,都会收到此错误.每当我们导航到我们的应用程序中的任何其他页面时,同步工作.
请注意,当然,我们可以关闭此页面的同步并将其视为非角度,但这只能被视为一种解决方法.
问题:
还有什么可以导致量角器到角度同步失败?我们应该检查什么?
而且,一般来说,在Protractor中调试同步问题的推荐方法是什么?
使用当前最新的Protractor 5.5.1,Angular 1.5.6.
解决方法:
好的,所以这个问题引起了我的兴趣,所以我想出了一个关于如何确定量角器等待的程序化解决方案:
var _injector = angular.element(document).injector();
var _$browser = _injector.get('$browser');
var _$http = _injector.get('$http');
var pendingTimeout = true;
//this is actually method that protractor is using while waiting to sync
//if callback is called immediately that means there are no $timeout or $http calls
_$browser.notifyWhenNoOutstandingRequests(function callback () {
pendingTimeout = false
});
setTimeout(function () {
//this is to differentiate between $http and timeouts from the "notifyWhenNoOutstandingRequests" method
if (_$http.pendingRequests.length) {
console.log('Outstanding $http requests', _$http.pendingRequests.length)
} else if (pendingTimeout) {
console.log('Outstanding timeout')
} else {
console.log('All fine in Angular, it has to be something else')
}
}, 100)
在plunker http://plnkr.co/edit/O0CkpnsnUuwEAV8I2Jil?p=preview中,您可以尝试超时和$http呼叫,我的延迟端点将在解决呼叫之前等待10秒,希望这对您有所帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。