This question is very close to the question asked in Using protractor with loops but still have not resolved by me in case of tiny difference.
// This script should print button names and its current numbers
var buttons = element.all(by.css('button'));
buttons.count().then(function(cnt){
for(var i=0;i<cnt;i++) {
var func = function(i2){ var k=i2; return function(){console.log("#"+k+", name: "+button_name);}}(i);
buttons.get(i).getText().then(func);
}
});
The compiler said "ReferenceError: button_name is not defined" that is right. How can I pass the button name inside then() function?