我在赛普拉斯测试中将get()的超时参数传递给should()时遇到问题

问题描述 投票:0回答:1
cy.get('.buy-order [data-cy=balance]', {timeout: 5000}).then(el => parseFloat(el.text())).should('be.greaterThan', balance);

我在将get()中的超时参数传递给上述代码中的should()时遇到问题。在then()中,我需要提取和修改将在should()中使用的数据。在下面的代码行中,超时参数正确地传递给了should()。因此,should()继续重试其指定的断言,直到在自定义超时时间内超时。此外,它会继续重试其指定的断言,直到正​​确为止。

cy.get('.buy-order [data-cy=balance]', {timeout: 5000}).should('be.greaterThan', balance);

但是在下面的代码行中,超时参数未传递给should()。我认为这是由中间的“ then”功能引起的。所以should()在自定义参数超时之前不会继续重试其指定的断言同样,它直到正确为止也不会继续重试其指定的断言。

cy.get('.buy-order [data-cy=balance]', {timeout: 5000}).then(el => parseFloat(el.text())).should('be.greaterThan', balance);

我该如何解决问题?

testing automation cypress e2e-testing
1个回答
0
投票

我认为您可以在should()中进行声明,这也将传播get()的超时:

cy.get('.buy-order [data-cy=balance]', {timeout: 5000})
  .should(el => expect(el.text()).to.be.greaterThan(balance));

https://docs.cypress.io/api/commands/should.html#Timeouts

© www.soinside.com 2019 - 2024. All rights reserved.