6

问题

调用repeater('#myTable tr','Rows').count();返回 a Future,而不是整数。我需要获取整数值,以便确认向表中添加了额外的行。

代码

it('should add a new user when save button is clicked',function()
    {
        showModal();

        //here I'm trynig to store the row count of my table into  a local variable.
        //a future is returned who's 'value' field is undefined.
        var memberCount = repeater('#memberTable tr','Member Rows').count();

        //this outputs 'undefined'
        console.log(memberCount.value);


        input('editedMember.name').enter('John');
        input('editedMember.grade').enter(5);
        input('editedMember.ladderPosition').enter(3);

        element('#saveMemberButton').click();
        sleep(1);
        expect(element(modalId).css('display')).toBe('none');

        //here is where I want to do the comparison against the above stored memberCount
        expect(repeater('#memberTable tr', 'Member Rows').count()).toBe(memberCount.value + 1);


    });

测试结果

Chrome 25.0 e2e should add a new user when save button is clicked FAILED
    expect repeater 'Member Rows ( #memberTable tr )' count toBe null
    /Users/jgordon/learning/chessClub/web-app/test/e2e/scenarios.js:45:3: expected null but was 6
Chrome 25.0: Executed 2 of 2 (1 FAILED) (1 min 4.117 secs / 1 min 3.773 secs)
4

4 回答 4

4

深入了解 Angularjs 的 e2e 支持的源代码会发现,您必须调用execute()才能Future让它填充其值。此外,当您打电话时,execute您必须提供“完成”功能,execute()否则 Testacular 将(奇怪的是!)跳过您的测试。

代码

var rowCountFuture = repeater('#memberTable tr','Member Rows').count();
        
        rowCountFuture.execute(function(){
        });
        
        var memberCount = rowCountFuture.value;

虽然我很高兴看到这个作品,但我担心可能会出现一些异步错误,而且,我觉得这是一个 hack,而不是正确的方法。有任何想法吗?

于 2013-01-28T17:25:32.530 回答
2

基于最新的量角器版本:

it('should add a new user when save button is clicked', function() {
    var memberCount;
    element.all(by.repeater('#memberTable tr','Member Rows')).count().then(function(value) {
        memberCount = value;
    });
    ...
    // then do all your entering user info, saving etc.
    ...
    browser.refresh(); // or however you want to load new data
    expect(element.all(by.repeater('#memberTable tr','Member Rows')).count()).toEqual(memberCount + 1);
});
于 2014-06-30T15:36:02.330 回答
1

我遇到了同样的问题,value并且调用execute(). 我发现这种方法更可靠:

var getCount = repeater('ul li').count();
getCount.execute(function(value) {
    expect(value).toEqual(3);
});
于 2013-08-09T04:21:05.860 回答
1

您可以在定位器返回的异步承诺中最轻松地做到这一点

element.all(By.repeater 'thing in things').then(function(elements){
      count = elements.length;
      expect(count).toEqual(3);
});
于 2014-04-22T02:37:37.413 回答