0

I am trying to return Array of Promise after processed my nested for loop.. Below is the code written to extract certain details from webpage using one of the protractor test framework..

this.getFulldetails = function () {
    let nameValues = [];
    return this.getAddressCount().then((values) => {
            for (let m = 0; m < values; m++) {
            browser.wait(EC.visibilityOf(element(by.css(getLinked(m)))), defaultWait),
                nameValues.push(browser.findElement(by.css(getLinkedAddressCnt(m))).getText());
            for (let i = 0; i < cValues; i += 1) {
                browser.wait(EC.visibilityOf(element(locators.nameValue)), defaultWait);
                nameValues.push(browser.findElement(by.css(getLinked(m)))
                    .findElement(by.css(getIndividual(i)))
                    .findElement(locators.nameValue)
                    .getText());
                nameValues.push(browser.findElement(by.css(getLinked(m)))
                    .findElement(by.css(getIndividual(i)))
                    .findElement(locators.periodValue)
                    .getText());
            }
        })
    }
    return Promise.all(nameValues)
    // return nameValues
    });
};

When I return just 'return nameValues' then it is returning array[10] elements however when I return Promise.all(nameValues) it is returning empty array []... how can I resolve the promise in the above code.. sorry I am not advanced javascript developer and not used much of promise

Ele
  • 33,468
  • 7
  • 37
  • 75
Jags
  • 111
  • 2
  • 7
  • 1
    note, your code is deceptively indented, and has errors with unbalanced `()` and `{}` – Jaromanda X Jan 16 '18 at 21:29
  • I have had checked looks fine and did not throw any error for that.. please explain – Jags Jan 16 '18 at 23:57
  • 1
    `looks fine` - well, it's not, put it in firefox scratchpad or jsfiddle, hit `pretty print` / `tidy` button - see how code changes, click on the } or ) above the return Promise.all line, see that they are RED, means there's a problem - so, the code you posted here is invalid anyway – Jaromanda X Jan 17 '18 at 00:03

0 Answers0