我需要在特定的 should
中自定义超时柏树中的命令。
我有这个具有全局超时的 json 文件:
{
"viewportWidth": 1600,
"defaultCommandTimeout": 10000
}
在特定情况下,我需要更高的超时时间,我想要这样的东西:
cy.get('body').should('contain','success', {timeout: 30000})
我该怎么做呢?顺便说一句,我不想覆盖默认命令超时,我需要一个特定的超时。
最佳答案
tl;博士
只需将超时传递给 get
, 它将传递给 should
.
cy.get('body', {timeout: 30000}).should('contain','success')
解释
这在
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
docs about timeouts 中更详细地解释了该技术。 .
关于javascript - Cypress :特定应该命令中的自定义超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56779120/