我需要在赛普拉斯的特定should
命令中自定义超时。
我有一个具有全局超时的json文件:
{
"viewportWidth": 1600,
"defaultCommandTimeout": 10000
}
在特定情况下,我需要更长的超时时间,我想要这样的事情:
cy.get('body').should('contain','success', {timeout: 30000})
我该怎么做?顺便说一句,我不想覆盖默认命令超时,我需要一个特定的超时。
答案 0 :(得分:1)
您可能希望将{timeout: 30000}
选项移至父命令,如下所示:
cy.get('body', {timeout: 30000}).should('contain','success')
通过这种方式,父命令的默认断言以及所有后续断言都将继承此超时并覆盖默认命令超时。 在此处阅读更多信息:https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Timeouts
答案 1 :(得分:0)
只需将超时传递给get
,它将超时传递给should
。
cy.get('body', {timeout: 30000}).should('contain','success')
这在should
's official documentation in the Timeouts section中有解释:
.should()
将继续retry其指定的断言,直到超时为止。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中有更详细的说明。