mardi 20 décembre 2016

How to retrieve data from protractor's promises chain?

I have a function, which correctly retrieves index of the element, which text === "check". It is clearly printed in console.log:

function getIndex() {
    return element.all(by.css(".palette__item.ng-scope>span")).then(function (colorList) {
        colorList.forEach(function (elem, index) {
            elem.getText().then(function (text) {
                if (text == "check") {
                    console.log(index);
                    return index;
                }
            });
        });
    });
}

Then, I've tried a lot of different approaches, how to retreive data from it, but haven't succeed. Tha last approach is this:

var res = null;
webDriver.promise.fullyResolved(getIndex()).then(function (index) {
    res = index;
});
console.log(res);

So, here I have tried to init res value inside the function, which guaratees any promise resolve, but it doesn't work, and returns null.

I think, that I have mistake in getIndex() function, maybe, I have placed return opertor in a wrong place, but I need help here. I have totally lost any idea how to make it work. Help, please.

Aucun commentaire:

Enregistrer un commentaire