使用 $resource 时量角器超时等待与页面同步

Protractor times out waiting for sync with page when using $resource(使用 $resource 时量角器超时等待与页面同步)
本文介绍了使用 $resource 时量角器超时等待与页面同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用一个小型 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 时量角器超时等待与页面同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)