如何将行数分配给另一个值,稍后可以在 Protractor 的测试用例中使用

How to assign count of number of rows to another value which can be use later in the test cases in Protractor

如何将行数分配给另一个值,以便稍后在 Protractor 的测试用例中使用。

我写了下面的代码,但它没有返回计数值:

var rows = element.all(by.repeater('row in renderedRows'));
var row1 = rows.count().then(function(rowsn) { 
        return rowsn;
        console.log(rowsn);
    });

现在我想在for循环中使用这个计数值

量角器通常return 承诺,而不是价值。因此,您需要在 then 或其他解决承诺的代码中进行计算。 你会想要阅读 the Protractor Control Flow doc and probably the WebDriverJS control flow doc

在你的情况下,是这样的:

var rowsPromise = element.all(by.repeater('row in renderedRows'));
rowsPromise.count().then(function(rowsn) { 
        for (var i = 0; i < rowsn; i++) {
            // do something with rowsPromise[i] (which is also a promise)
        }
    });