如何在量角器中的 ng-repeat 中使用 isElementPresent/isPresent?

How to use isElementPresent/isPresent inside ng-repeat in protractor?

HTML:

<div ng-repeat="todo in todos">
        <span><input ng-model="todo.title" /></span>
        <span><input ng-model="todo.time" /></span>
        <span><input ng-model="todo.name" /></span>
</div>

通过测试:

expect(element(by.repeater('todo in todos')).isPresent()).toBe(true);

通过测试:

expect(element(by.repeater('todo in todos').row(1)).isPresent()).toBe(true);

测试 1 失败:

Expected false to be true.

expect(element(by.repeater('todo in todos').row(1).column('todo.name')).isPresent()).toBe(true);

测试 2 失败:

Expected false to be true.

browser.isElementPresent(element(by.repeater('todo in todos').row(1).column('todo.name'))).then(function(present){
    expect(present).toBe(true);
})

在项目级别,我可以在字段中设置数据。在项目级别,我可以在字段中检索数据。但无法在项目级别使用 isPresentisElementPresent

这里的问题是 .column('todo.name') would search for elements bound to todo.name. In other words, it would make a search by binding (see findRepeaterElement),而你将 todo.name 定义为 ng-model

引用@juliemr(问题ng-repeat with ng-model bindings):

the column selector takes a string which matches bindings, not input ng-models.

成功了!仅当存在输入时,此代码才会 sendKeys

我在 webstorm 中调试了这段代码并这样做了:

element.all(by.repeater('todo in todos')).then(function(allrows){

    for(var i = 0 ;i<allrows.length ;i++)
    {
        allrows[i].all(by.model('todo.name')).then(function(field){

            field[0].isPresent().then(function(val){

                expect(val).toBe(true);

                field[0].sendKeys('22.335');

            });
        });
    }
});