调试量角器到角度同步问题的规范方法 [英] Canonical way to debug Protractor-to-Angular sync issues

查看:100
本文介绍了调试量角器到角度同步问题的规范方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述:

我们最近在量角器端到端测试中打开应用程序中的页面之一时遇到了这个臭名昭著的错误:

We've recently got this infamous error while opening one of the pages in our application in a Protractor end-to-end test:

失败:超时,等待异步Angular任务在50秒后完成.这可能是因为当前页面不是Angular应用程序.

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/");调用上发生的:

This happens on a browser.get("/some/page/"); call in one of our tests:

describe("Test", function () {
    beforeEach(function () {
        browser.get("/some/page/");
    });

    it("should test something", function () {
        // ...
    });
)};

而且,我们的情况很奇怪,就是该错误未在Angular Web应用程序的任何其他页面上引发-量角器与Angular同步没有任何问题. ng-app在所有页面上位置相关的内容都是相同的-ng-app是在根html标记上定义的:

And, what is weird about our case, is that the error is not thrown on any other page in our Angular web application - Protractor syncs with Angular without any problems. ng-app location-wise things are the same across all the pages - ng-app is defined on the root html tag:

<html class="ng-scope" lang="en-us" ng-app="myApp" ng-strict-di="">

行为是一致的-每次我们使用browser.get()导航到此页面时,都会收到此错误.每当我们导航到应用程序中的任何其他页面时,同步均有效.

The behavior is consistent - every time we navigate to this page with browser.get(), we get this error. Any time we navigate to any other page in our app, sync works.

请注意,当然,我们可以关闭此页面的同步并将其视为非角度同步,但这只能被视为一种解决方法.

Note that, of course, we can turn the sync off for this page and treat it as non-angular, but this can only be considered as a workaround.

问题:

还有哪些会导致量角器到角度同步失败?我们应该检查什么?

What else can cause Protractor-to-Angular sync fail? What should we check?

通常,在量角器中调试同步问题的推荐方法是什么?

使用当前最新的Protractor 5.5.1,Angular 1.5.6.

推荐答案

好,这个问题引起了我的兴趣,所以我想出了一个编程的解决方案来确定如何等待量角器:

Ok, so that question intrigued me so I came up with a programmatic solution on how to determine what protractor is waiting for:

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)

这里有塞子 http://plnkr.co/edit/O0CkpnsnUuwEAV8I2Jil?p=preview 您可以尝试超时和$ http呼叫,我的延迟端点将在解决呼叫之前等待10秒钟,希望对您有帮助

Here in the plunker http://plnkr.co/edit/O0CkpnsnUuwEAV8I2Jil?p=preview you can experiment with the timeout and the $http call, my delayed endpoint will wait for 10 seconds before resolving the call, hope that this will be helpful for you

这篇关于调试量角器到角度同步问题的规范方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆