【问题标题】:Cypress: custom timeout in specific should command赛普拉斯:特定应该命令中的自定义超时
【发布时间】:2019-06-26 18:34:11
【问题描述】:

我需要在 cypress 的特定 should 命令中设置自定义超时。 我有这个具有全局超时的 json 文件:

{
  "viewportWidth": 1600,
  "defaultCommandTimeout": 10000
}

有一种特殊情况,我需要更高的超时时间,我想要这样的:

cy.get('body').should('contain','success', {timeout: 30000})

我该怎么做?顺便说一句,我不想​​覆盖默认命令超时,我需要一个特定的超时。

【问题讨论】:

    标签: javascript cypress


    【解决方案1】:

    tl;博士

    只需将超时传递给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 中更详细地解释了该技术。

    【讨论】:

      【解决方案2】:

      您可能希望将 {timeout: 30000} 选项移至父命令,如下所示:

      cy.get('body', {timeout: 30000}).should('contain','success')
      

      以这种方式,父命令的默认断言和所有后续断言都继承此超时,覆盖默认命令超时。 在这里阅读更多:https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Timeouts

      【讨论】:

        猜你喜欢
        • 2021-03-01
        • 2019-06-05
        • 1970-01-01
        • 2020-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多