我在Cypress测试中有随机超时 [英] I have random timeouts in cypress tests

查看:93
本文介绍了我在Cypress测试中有随机超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在与cypress一起工作了3个月,而现在尝试解决这个问题已有2个月了,我现在真的不知道如何解决它。

I'm working with cypress now for 3 months and I try to fix this problem for 2 months now and i really don't now how to fix it.

当我运行所有测试时,很多测试都失败了。并且每次都是另一项测试(随机)。

When i run all my tests there are a lot of tests failing. And every-time its another test (random).

我正在测试的应用程序具有禁用的按钮,当字段中填充文本时,该按钮将变为活动状态。
,但问题是当按钮仍处于禁用状态时,柏树会单击按钮。该按钮需要一些时间才能激活,现在我在代码中输入了以下内容:

The application that i'm testing has an button that is disabled and when the fields are stuffed with text, the button becomes active. but the problem is that cypress clicks on the button when the button is still disabled. the button needs some time to get active, now I have put the following in the code:


  • cy.wait('@ budgetblindsPost')

  • cy.wait(500)

但是这也不起作用。我的错误较少,但是仍然会出错。

But this is also not working. I have less errors but I still get errors.

这是我收到的错误示例

这也是我的代码示例

推荐答案

使用 cy.wait()可能最终可以解决与超时有关的问题,但会使您的测试套件不必要地变慢。相反,您应该增加超时时间

Using cy.wait() all over the place may eventually solve issues related to timeout, but will make your test suite unnecessarily slow. Instead, you should increase the timeout(s)

此命令仅在30分钟后失败找不到对象的秒数,或者找到对象后的30秒。

This command will only fail after 30 seconds of not being able to find the object, or, when it finds it, 30 seconds of not being able to click it.

cy.get('#model_save', {timeout: 30000}).click({timeout: 30000});

请注意,您的 500 值表示半秒钟,可能还不够。

Please note that your value of 500 means half a second, which may not be enough.

如果您发现自己用在很多地方都使用相同的值,您可能希望为所有中的值增加一次

If you find yourself overriding the timeout with the same value in a lot of places, you may wish to increase it once for all in the config.


defaultCommandTimeout:4000

等待大多数基于DOM的时间(以毫秒为单位)命令被认为是超时的

defaultCommandTimeout: 4000
Time, in milliseconds, to wait until most DOM based commands are considered timed out

这篇关于我在Cypress测试中有随机超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆