Skip to content
Discussion options

You must be logged in to vote

Please read our documentation that explains how every test command is queued and is asynchronous https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous

In your example:

createItem()
console.log(`ID is now: ${item.id}`)

cy.visit(`/item/${item.id}`)

the console.log immediately executes, while createItem and cy.visit are enqueued to be executed. If you want the console.log execute to run AFTER the Cypress commands inside createItem finish, then you can do one of these things

createItem()
cy.then(() => {
  console.log(`ID is now: ${item.id}`)
})

cy.visit(`/item/${item.id}`)

or return Cypress object from createItem which allows you to chain more t…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jgonzalezalbisu
Comment options

@rrauenza
Comment options

Answer selected by unikitty37
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants