I need to have custom timeout in a specific should
command in cypress.
I have this json file which has global timeout:
{
"viewportWidth": 1600,
"defaultCommandTimeout": 10000
}
There is a specific case that I need a higher timeout, I would like something like this:
cy.get('body').should('contain','success', {timeout: 30000})
how do I do this? BTW, I do not want to override default command timeout, I need a specific timeout.
Just pass the timeout to get
, it will pass it down to should
.
cy.get('body', {timeout: 30000}).should('contain','success')
This is explained in should
's official documentation in the Timeouts section:
.should()
will continue to retry its specified assertions until it times out.cy.get('input', { timeout: 10000 }).should('have.value', '10') // timeout here will be passed down to the '.should()' // and it will retry for up to 10 secs
The technique is explained in greater detail in the docs about timeouts.
You probably want to move your {timeout: 30000}
option to the parent command, like this:
cy.get('body', {timeout: 30000}).should('contain','success')
In this way the parent command's default assertions, and all subsequent assertions inherit this timeout overriding the default command timeout. Read more here: https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Timeouts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With