【发布时间】:2021-01-02 03:23:40
【问题描述】:
由于在标题文本上设置了断言,我的赛普拉斯测试行为不一致。这是我的代码:
cy.get('.heading-large').should('contain', 'dashboard') // passes
cy.contains('View details').first().click()
cy.get('.heading-large').should('contain', 'Registration details') // sometimes fails
如果失败,那是因为标题仍然包含“仪表板” - 赛普拉斯似乎没有重试,但给出错误 Timed out retrying: expected '<h1.heading-large>' to contain 'Registration details'
通过阅读Cypress retry-ability,我的理解是should 断言应该一直尝试直到超时,超时设置为"defaultCommandTimeout" : 5000。即使我有一个跨两个页面具有相同标识符的元素,这感觉也是正确的。我正在测试的应用没有重大性能问题。
如果我不看窗口,测试似乎更有可能失败,this issue 似乎是一个可能的原因。
谁能帮助确定:我的测试或赛普拉斯是否存在问题,我该如何改进测试?我在 MacOS Catalina 上使用 Cypress 5.1.0 和 Chrome 85。
【问题讨论】:
-
您是否按照“仅当测试运行程序的浏览器失去焦点(或无头运行)”问题中的建议尝试
.click({ force: true })?由于 CSS 设置,一些元素没有actionability,{ force: true }告诉赛普拉斯绕过规则。 -
感谢 eric99,我刚刚尝试过,但当窗口失焦时仍然出现相同的断言错误。它看起来越来越像我需要等待flake issue 得到解决,同时观察运行的测试!
标签: cypress