Skip to content

Commit

Permalink
Remove outdated double-await issue in docs (#7707)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Bromann <mail@christian-bromann.com>
  • Loading branch information
klamping and christian-bromann committed Nov 18, 2021
1 parent 5d2de46 commit 3a73bd8
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions website/docs/SyncVsAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ describe('suite async', () => {

console.log(browser.capabilities) // static properties should not be awaited

// this WON'T WORK! You can't chain functions like this.
await $('body').click()
// instead you need to:
await (await $('body')).click()
})
})
```
Expand All @@ -101,23 +98,19 @@ describe('suite async', () => {

There can be quite some confusion when handling asynchronous commands manually. The usual problems are:

- chaining of element commands:

```js
await $('body').click()` // throws `$(...).click is not a function`
```

You can't chain element calls as you have to await multiple asynchronous functions. To fix this, first await element then trigger the click, like so:
- previous command was not awaited:

```js
const el = await $('body')
el.waitForExist() // ERROR: await is missing here, you'll get `Unhandled promise rejection`.
await el.click()
```

- previous command was not awaited:
- Array loops (e.g., `forEach` & `map`) need `Promise.all`

```js
const el = await $('body')
el.waitForExist() // ERROR: await is missing here, you'll get `Unhandled promise rejection`.
await el.click()
const links = await $$('a')
const linksText = await links.map((link) => {
return link.getText();
})
```

0 comments on commit 3a73bd8

Please sign in to comment.