关于量角器中then函数的参数。在下面的代码中,什么将传递给“值”?

时间:2018-08-20 05:54:39

标签: javascript protractor

如果bar等于jsonObj.alias,则应返回true或false,并且应该是next函数的参数。但这不是在这里发生。请清除这一点。最后一个then函数的参数是什么?如何?

element
    .all(by.repeater('portGroup in displayedCollection'))

    .filter(function(eachRow) {
        return eachRow.element(by.css('td:nth-child(2)')).getText().then(function(bar){
            return bar === jsonObj.alias;
        });
    })

    .then(function(values){
        values[0].element(by.css('span[class="ng-binding"]')).click();
    }); 

1 个答案:

答案 0 :(得分:0)

将代码分为两部分,可以使您理解问题。

var satisfiedRows = element
    .all(by.repeater('portGroup in displayedCollection'))

    .filter(function(eachRow) {
        // the filter function is to find out from all rows 
        // which's 3rd cell text equal to `jsonObj.alias`
        return eachRow.element(by.css('td:nth-child(2)')).getText().then(function(bar){
            return bar === jsonObj.alias;
        });
    });  // we can split your code at here


    // satisfiedRows is a promise which eventual value are satisfied rows
    // you call `then()` on this promise, the argument `function()` will be 
    // passed-in the promise's eventual value. In your case, 
    // they are rows which's 3rd cell text equal to `jsonObj.alias`
    satisfiedRows.then(function(rowsAfterFilter){
        rowsAfterFilter[0].element(by.css('span[class="ng-binding"]')).click();
    });