I am working with JavaScript in protractor environment for E2E tests.
I read a lot of closure and promises on JavaScript, however I still can't understand what is wrong in my code.
I try to get back from the following function specific string value from tag element (which contain few tags).
Can someone please explain what is wrong there?
In the debug messages I got the correct value, but the function always returns the initial value of group_name ( means: "tmp").
Below is the fuction I wrote in my page object:
this.retreive_participant_name_by_idx = function(idx){
var group_name="tmp";
element.all(by.repeater(this.group_participant_repeater()))
.then(function(rows) {
console.log("before assign " + group_name);
element.all(by.repeater("tag in tagList.items track by track(tag)"))
.get(idx)
.then(function(row){
row.getText().then(function (txt) {
group_name = txt;
console.log("Item name " + group_name + "!!!!!");
return group_name;
});
});
});
return (group_name);
};