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);
我该如何解决问题?
我认为您可以在should()
中进行声明,这也将传播get()
的超时:
cy.get('.buy-order [data-cy=balance]', {timeout: 5000})
.should(el => expect(el.text()).to.be.greaterThan(balance));