0

I currently have two methods like this:

  getCell(lineItemRow, columnName) {
    return this.getColumnIndexOfColumn(columnName)
      .then(function(columnIndex) {
        sleep(10000);
        return new Element(`//div[@class='ember-view scrollableTableRow'][${lineItemRow}]//div[@class='scrollableTableCell '][${columnIndex}]`)}
    );
  }

  getColumnIndexOfColumn(columnName) {
    let b = this.browser;
    return this.getColumnTitles()
      .then(function(columnTitles) {
        let titles = columnTitles.value.map(function(element) { return b.elementIdText(element.ELEMENT) });
        Promise.all(titles)
        .then(function (results) {
          var formatted = results.map(function(title) {return title.value;});
          return formatted.indexOf(columnName);
        }).then(function (value) { console.log(value); return value; })
      })
   }

The problem I'm having is that when getCell calls this.getColumnIndexOfColumn(columnName), the value that is resolved is undefined, rather than being the proper index. I can verify that the formatted.indexOf(columnName) call returns the correct index. How would I make getColumnIndexOfColumn resolve with the value of formatted.indexOf(columnName)?

Thanks

Arthur Lee
  • 121
  • 1
  • 2
  • 14
  • 1
    Don't you miss a `return` in your last callback ? Maybe you want to return the `Promise` you build in there ? – LeGEC Mar 07 '17 at 22:06
  • Possible duplicate of [setting a variable to get return from call back function using promise](http://stackoverflow.com/questions/22536385/setting-a-variable-to-get-return-from-call-back-function-using-promise) – AmericanUmlaut Mar 07 '17 at 22:06
  • @LeGEC That was indeed the problem. Thanks! – Arthur Lee Mar 07 '17 at 22:21
  • 1
    What is `sleep(10000)`? That does not look like Javascript or a good idea in Javascript. – jfriend00 Mar 07 '17 at 22:56
  • That was a method that I made which just creates a promise and resolves it after x milliseconds. – Arthur Lee Mar 08 '17 at 15:56

1 Answers1

0

Was missing a return in front of Promise.all(titles), so it wasn't returning the callback result.

Arthur Lee
  • 121
  • 1
  • 2
  • 14