In the code below, I'm using a repeater to get the values from ng-repeat and getting the column by cat.name which gives me an array of all the cat names. So I'm doing a for loop to get to a particular name, say Meow, I want to store the index value, so that I can validate whether the corresponding row, the cat's age to be equal to 10. The 2 console.log of index inside the for loop results in different values, the first one ranges from 0-10 (considering the length of the array as 10) and the next always results in 10. It logs "10" 10 times. Now, I cannot get the index to validate the corresponding row, since i is always 10. Can someone correct me where I'm going wrong and also answer me with the modified code. I guess I'm going wrong in chaining the promise
element(by.repeater(cat in cats).column(cat.name)).then(function(fields) {
for (var i in fields) { // promise returns an array fields
console.log(i); // values range from 0 to length of the fields(say 10)
fields[i].getText().then(function(fieldValue) {
console.log(i); // values are always 10 (i.e the length of the array)
if(fieldValue === 'Meow') {
var catAge= element(by.repeater('cat in cats').row(i)).element(by.model('cat.age')); // row(i) always gives the last value
expect(catAge.getAttribute('value')).toBe('10');
}
})
}
});