简体   繁体   English

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

[英]Protractor times out waiting for sync with page when using $resource

I'm testing Protractor with a small AngularJS app. 我正在使用一个小型AngularJS应用程序测试Protractor。

This is the test: 这是测试:

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

Controller: 控制器:

angular.module('myApp.controllers', []).
  controller('DraftsCtrl', ['$scope', 'Draft', function($scope, Draft) {
    $scope.drafts = Draft.query();
}])

Draft service: 服务草案:

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: 使用Protractor运行此测试会导致以下错误:

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

to this: 对此:

$scope.drafts = [];

The test fails as expected, but more importantly: it does not time out. 测试按预期失败,但更重要的是:它没有超时。

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. 启用query()后,无论是在浏览器中手动运行应用程序还是查看Protractor打开的浏览器窗口时,API返回的数据都由转发器正确显示。

Why is Protractor not able to synchronize with the page when the service is communicating with the API? 为什么当服务与API通信时,Protractor无法与页面同步?

AngularJS is v1.2.0-rc3. AngularJS是v1.2.0-rc3。 Protractor is v0.12.0. 量角器是v0.12.0。

This is a known issue , but there is a temporary workaround. 这是一个已知问题 ,但有一个临时解决方法。 Set ptor.ignoreSynchronization = true . 设置ptor.ignoreSynchronization = true

For example: 例如:

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

browser.ignoreSynchronization = true; worked out for me. 为我工作了。

I'm using Protractor 3.3.0 and to get this to work in my test I had to defer the ignore synchronisation until after I had done the setup. 我正在使用Protractor 3.3.0并且为了在我的测试中使用它,我不得不推迟忽略同步,直到我完成设置。

So in my beforeEach I call my action: 所以在我之前我每次都叫我的行动:

var searchBox = element(by.css('#inpt_search'));
searchBox.sendKeys('test');

I then have to wait for the mock backend to populate the view (I'm not happy about these sleep calls so if anyone has a better way of doing this please comment, I can't get expectedConditions.presenceOf to work as it's part of the same bug) using browser.sleep(500) . 然后我必须等待模拟后端填充视图(我对这些sleep调用不满意所以如果有人有更好的方法这样做请评论,我不能得到expectedConditions.presenceOf工作,因为它的一部分同样的错误)使用browser.sleep(500) Then in the test I set browser.ignoreSynchronization = true which unblocks whatever is blocked and sees the browser content. 然后在测试中我设置browser.ignoreSynchronization = true ,取消阻止被阻止的内容并查看浏览器内容。

describe('standard search', function (){
    beforeEach(function (){
        openApp();
        var searchBox = element(by.css('#inpt_search'));
        searchBox.sendKeys('test');
        browser.sleep(500);
    });
    it('should work or summat', function () {
        browser.ignoreSynchronization = true;
        var fileItems = element.all(by.repeater('item in list'));
        expect(fileItems.count()).toEqual(50);
    });
});

Instead of using browser.ignoreSynchronization , use browser.waitForAngularEnabled(*boolean*) . 而不是使用browser.ignoreSynchronization ,请使用browser.waitForAngularEnabled(*boolean*) browser.waitForAngularEnabled(false) sets browser.ignoreSynchronization to true , browser.waitForAngularEnabled(true) sets browser.ignoreSynchronization to false . browser.waitForAngularEnabled(false)browser.ignoreSynchronization设置为truebrowser.waitForAngularEnabled(true)browser.ignoreSynchronization设置为false

you can also include this as part of your test suites' config file: 您还可以将此作为测试套件配置文件的一部分包含在内:

onPrepare: function () {
    'use strict';
    browser.waitForAngularEnabled(false);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 量角器超时等待元素 - Protractor Times Out Waiting For Element 量角器“等待量角器与页面同步时出错”浏览Angular站点 - Protractor “Error while waiting for Protractor to sync with the page” browsing Angular site 使用量角器时,单击导致发出http请求的按钮时,我收到此消息:等待量角器同步时出错 - While using Protractor, when clicking a button which causes an http request to be made, I receive this: error while waiting for protractor to sync 在等待量角器与页面同步时刷新时发生错误,在捕获警报时 - Error while waiting for protractor to sync with the page on catching alert during refresh 错误:在11001ms之后等待Protractor与页面同步超时。“当用户browser.getCurrentUrl()时 - Error: Timed out waiting for Protractor to synchronize with the page after 11001ms." when user browser.getCurrentUrl() 等待量角器与页面同步时出错:在运行量角器测试用例时“在窗口中找不到角度” - Error while waiting for Protractor to sync with the page: “angular could not be found on the window” on running protractor test case 执行量角器测试时出现“失败:等待量角器与页面同步时出错” - "Failed: Error while waiting for Protractor to sync with the page" while executing Protractor tests 量角器不等待页面加载 - Protractor not waiting for page load 失败:等待量角器与页面同步时出错:“在窗口中找不到角度” - Failed: Error while waiting for Protractor to sync with the page: “angular could not be found on the window” 带有 protractorjs 的 Angular 2 失败:等待 Protractor 与页面同步时出错:“window.getAllAngularTestabilities 不是函数” - Angular 2 with protractorjs Failed: Error while waiting for Protractor to sync with the page: "window.getAllAngularTestabilities is not a function"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM