Cypress未遵守我的单个命令超时设置。

huangapple go评论83阅读模式
英文:

Why isnt cypress honoring my timeout for a single command?

问题

以下是您要翻译的内容:

"I'm a couple of weeks into cypress test automation (cypress V12) and while it seems cool I am confused by what I am seeing.

I have code that looks like this:

it('shows the problem for Stack Overflow', {defaultCommandTimeout: 20000}, function () {
//bunch of commands that do stuff are here but I dont think they are related to the issue...

const loadingSpinnerLocator = ".k-loader-canvas";
cy.get(loadingSpinnerLocator).should('be.visible');
cy.get(loadingSpinnerLocator).should('not.exist' ,{ timeout: 15000 });

})

this code works fine because I am doing a workaround in the top line and overriding the defaultCommandTimeout to 20 seconds.

If I remove the override on the "it statement" the test fails when we are making sure that the spinner is gone after 4 seconds. Isn't my code saying to look for 15 seconds???

How do I tell cypress to "wait up to 15 seconds for the loading spinner to not be there" without bumping up the timeout for the whole test??"

英文:

I'm a couple of weeks into cypress test automation (cypress V12) and while it seems cool I am confused by what I am seeing.

I have code that looks like this:

    it('shows the problem for Stack Overflow', {defaultCommandTimeout: 20000}, function () {
      //bunch of commands that do stuff are here but I dont think they are related to the issue...

      const loadingSpinnerLocator = ".k-loader-canvas";
      cy.get(loadingSpinnerLocator).should('be.visible');
      cy.get(loadingSpinnerLocator).should('not.exist' ,{ timeout: 15000 });          

    })

this code works fine because I am doing a workaround in the top line and overriding the defaultCommandTimeout to 20 seconds.

If I remove the override on the "it statement" the test fails when we are making sure that the spinner is gone after 4 seconds. Isn't my code saying to look for 15 seconds???

How do I tell cypress to "wait up to 15 seconds for the loading spinner to not be there" without bumping up the timeout for the whole test??

答案1

得分: 3

一般来说,{ timeout: 15000 } 是一个选项对象。

所有 Cypress 命令都在语法部分有文档,其中告诉您是否可以传递选项,例如 .should()

> 语法
> js > .should(chainers) > .should(chainers, value) > .should(chainers, method, value) > .should(callbackFn) >

这告诉您.should()没有选项语法。

另一方面,对于 .get(),有允许传递 options 参数的不同排列方式,

> 语法
> js > cy.get(selector) > cy.get(alias) > cy.get(selector, options) > cy.get(alias, options) >

英文:

Generally speaking, { timeout: 15000 } is an options object.

All Cypress commands are documented with a Syntax section which tells you if you can pass options, for example .should()

> Syntax
> js
> .should(chainers)
> .should(chainers, value)
> .should(chainers, method, value)
> .should(callbackFn)
>

This tells you there is no options syntax for .should().

On the other hand for .get(), there are permutations that allow an options parameter,

> Syntax
> js
> cy.get(selector)
> cy.get(alias)
> cy.get(selector, options)
> cy.get(alias, options)
>

huangapple
  • 本文由 发表于 2023年8月4日 22:55:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定