简体   繁体   中英

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

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

I have written following code but its not returning count value:

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

Now i want to use this count value in for loop

Protractor functions generally return promises, not values. So, you need to do your computation in a then or other code that resolves the promise. You'll want to read the Protractor Control Flow doc and probably the WebDriverJS control flow doc

In your case, some thing like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM