You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even if it's a really important point, at the time of writing (May, 2019) it seems that waiting for XHR requests and responses is not so
236
-
common. With exceptions for Cypress and Puppeteer, other tools/frameworks force you to look for
237
-
something in the DOM that reflects the XHR result instead of looking for the XHR request itself. You can read more about th topic:
238
-
239
-
- Selenium WebDriver: [5 Ways to Test AJAX Calls in Selenium WebDriver](https://www.blazemeter.com/blog/five-ways-to-test-ajax-calls-with-selenium-webdriver)
240
-
- TestCafé: [Wait Mechanism for XHR and Fetch Requests](https://devexpress.github.io/testcafe/documentation/test-api/built-in-waiting-mechanisms.html#wait-mechanism-for-xhr-and-fetch-requests)
241
-
- DOM Testing Library: [await API](https://testing-library.com/docs/dom-testing-library/api-async#wait)
242
-
243
-
<br /><br />
244
-
245
-
## Custom waitings
246
-
247
-
The various UI testing tools/frameworks have built-in solutions to perform a lot of checks, but let's
248
-
concentrate on writing a custom waiting. Since UI testing is 100% asynchronous, a custom waiting
249
-
should face recursive promises, a concept not so handy to manage at the beginning.
250
-
251
-
Luckily, there are some handy solutions and plugins to help us with that. Consider if we want to
252
-
wait until a global variable (`foo`) is assigned with a particular value (`bar`): below you are going to
253
-
find some examples.
254
-
255
-
### Code Examples
256
-
257
-
Cypress
258
-
259
-
Thanks to the [cypress-wait-until plugin](https://github.com/NoriSte/cypress-wait-until) you can do:
<aid="footnote1">1</a>: unlike Cypress, Puppeteer, etc. DOM Testing Library is quite a different tool, that's why the examples are not available for every single part.
_Crossposted by [NoriSte](https://github.com/NoriSte) on [dev.to](https://dev.to/noriste/await-do-not-make-your-e2e-tests-sleep-4g1o) and [Medium](https://medium.com/@NoriSte/react-hooks-memorandum-bf1c2758a672)._
0 commit comments