用于调试Protractor-Angular同步问题的规范方法

ale*_*cxe 11 javascript selenium angularjs protractor

问题描述:

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

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

browser.get("/some/page/");在我们的一个测试中的调用中发生:

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

    it("should test something", function () {
        // ...
    });
)};
Run Code Online (Sandbox Code Playgroud)

并且,我们的案例有点奇怪的是,我们的Angular Web应用程序中的任何其他页面都没有抛出错误 - Protractor与Angular同步而没有任何问题.ng-app所有页面的位置相同的东西都是相同的 - ng-app在根html标签上定义:

<html class="ng-scope" lang="en-us" ng-app="myApp" ng-strict-di="">
Run Code Online (Sandbox Code Playgroud)

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

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

问题:

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

而且,一般来说,在Protractor中调试同步问题的推荐方法是什么?

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

mau*_*ycy 7

好的,这个问题引起了我的兴趣,所以我提出了一个关于如何确定量角器正在等待的程序化解决方案:

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)
Run Code Online (Sandbox Code Playgroud)

在这里的plunker http://plnkr.co/edit/O0CkpnsnUuwEAV8I2Jil?p=preview你可以试验超时和$ http调用,我的延迟端点将等待10秒才解决呼叫,希望这会有所帮助为了你