使用$资源时,量角器超时等待与网页同步 [英] Protractor times out waiting for sync with page when using $resource

查看:124
本文介绍了使用$资源时,量角器超时等待与网页同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用小AngularJS应用测试量角器。

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')
    }])

运行使用量角器导致以下错误这个测试:

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 = [];

如预期,但更重要的是测试失败。

通过查询启用(),无论是在浏览器中手动运行应用程序时,看着由量角器打开浏览器窗口时,该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​​通信?

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);
  });
});

这篇关于使用$资源时,量角器超时等待与网页同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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