title: Using ElementArrayFinder.filter() with async/await
body: <p>I've been using the following function to filter element arrays for the past few years with Webdriver's Control Flow enabled:</p>
  
  <pre><code>filterElementsByText (elemList, comparator, locator) {
    return elemList.filter((elem) =&gt; {
      let searchTarget = locator ? elem.element(locator) : elem
      return searchTarget.getText().then((text) =&gt; text === comparator)
    })
  }
  </code></pre>
  
  <p>I am now trying to migrate my repo to using async/await which requires turning off the Control Flow.</p>
  
  <p>This transition has been mostly successful, but I'm having trouble with the function above.  Intermittently, I am seeing this error:</p>
  
  <blockquote>
    <p>Failed: java.net.ConnectException: Connection refused: connect</p>
  </blockquote>
  
  <p>I am able to reproduce this issue with a test case I've written against <a href="https://angularjs.org" rel="nofollow noreferrer">https://angularjs.org</a>, although it happens with much higher frequency against my own app.</p>
  
  <pre><code>let todoList = element.all(by.repeater('todo in todoList.todos'))
  let todoText = element(by.model('todoList.todoText'))
  let todoSubmit = element(by.css('[value="add"]'))
  
  let addItem = async (itemLabel = 'write first protractor test') =&gt; {
    await todoText.sendKeys(itemLabel)
    return todoSubmit.click()
  }
  
  let filterElementsByText = (elemList, comparator, locator) =&gt; {
    return elemList.filter((elem) =&gt; {
      let searchTarget = locator ? elem.element(locator) : elem
      return searchTarget.getText().then((text) =&gt; {
        console.log(`Element text is: ${text}`)
        return text === comparator
      })
    })
  }
  
  describe('filter should', () =&gt; {
    beforeAll(async () =&gt; {
      browser.ignoreSynchronization = true
      await browser.get('https://angularjs.org')
  
      for (let i = 0; i &lt; 10; i++) {
        await addItem(`item${i}`)
      }
      return addItem()
    })
  
    it('work', async () =&gt; {
      let filteredElements = await filterElementsByText(todoList, 'write first protractor test')
      return expect(filteredElements.length).toEqual(1)
    })
  })
  </code></pre>
  
  <p>This is being run with the following set in Protractor's conf file: </p>
  
  <pre><code>SELENIUM_PROMISE_MANAGER: false
  </code></pre>
  
  <p>With the simplified test case it seems to occur on 5-10% of executions (although, anecdotally it does seem to occur more frequently once it occurs the first time)</p>
  
  <p>My problem is, this feels like a bug in Webdriver, but I'm not sure what conditions would cause that error so I'm not sure how to proceed.</p>