Currently, I am working with Angularjs Protractor for end-to-end testing and faced an issue while trying to calculate the sum of values in a column. Although I am able to print out each value within the loop successfully, I am struggling to figure out how to add them all together. Whenever I attempt to return the total after the loop, it turns out to be undefined.
function getTotal() {
ptor.findElements(protractor.By.className('col33')).then(function(promColCells) {
var total;
for (var i = 2; i < promColCells.length; i += 2) {
promColCells[i].getText().then(function(promCellString) {
total += parseFloat(promCellString);
});
}
return total;
});
};