13 Cypress Synchronization - biswajitsundara/Cypress GitHub Wiki
- Cypress is asynchronous in nature as it's a java script/type script product. However cypress team has taken care of it in the backend. Cypress first runs through whole code and puts commands in queue. Once code is in queue, next command in queue will only run after all callbacks of current command are completed, thus we can use above code pattern. So use aliases.
- Don't write additional methods for cypress commands to make it synchronous, it will break. For example don't use
async await
- Don't mix cypress commands and other synchronous commands, use
.then()
to create sequence - Incase of cypress chained command, it will execute in synchronous way.
- However if we chain non cypress commands like
jquery
etc with cypress commands then it won't run in synchronous way. - Example:
console.log
is asynchronous so it executes before the cypress test even starts. So use it in conjuction with then command
cypress.promise.all cypress chainable bluebird promise
https://docs.w3cub.com/cypress/api/utilities/promise
- https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Not-Promises
- https://www.toolsqa.com/cypress/cypress-asynchronous-nature/
- https://www.youtube.com/watch?v=01RTj1MWec0
- http://bluebirdjs.com/docs/api/promise.all.html
- https://github.com/bahmutov/cypress-promise-all-test
- https://stackoverflow.com/questions/58285668/gather-results-from-multiple-cypress-promisses
- https://github.com/cypress-io/cypress/issues/915
- https://stackoverflow.com/questions/58285668/gather-results-from-multiple-cypress-promisses
- https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html
- https://brucelefebvre.com/blog/2019/08/26/cypress-gotchas-with-promises/
- https://11sigma.com/blog/2019-05-08--core-cypress-lessons-we-learned-that-10x-ed-our-automation
- https://spin.atomicobject.com/2014/12/17/asynchronous-testing-protractor-angular/
- https://www.sohamkamani.com/blog/2016/03/14/wrapping-your-head-around-async-programming/
- https://bridge360blog.com/2015/05/05/improving-protractor-tests-using-shared-functions-and-promises/