我在 cypress 测试中将 get() 中的超时参数传递给 should() 时遇到问题
I have an issue to pass a timeout param in get() to should() in my cypress test
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));
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));