【发布时间】:2019-01-10 13:59:52
【问题描述】:
在赛普拉斯中,我想创建一个方法,如果条件合适,它将运行其他方法。
代码:
sizeOfTableShouldBeChangedAfterResizingIfThereAreManyData() {
cy.get('.footerWrapper').then(div => {
if(div.find('.pagination').length) {
cy.get('.pagination > .page').its('length').then(numberOfPages => {
if(numberOfPages > 3) {
this.numberOfRowsShouldBeEqualAtLeast(10)
this.changeNumberOfDisplayedRowsByIndex(1)
this.numberOfRowsShouldBeEqualAtLeast(20)
this.changeNumberOfDisplayedRowsByIndex(0)
this.numberOfRowsShouldBeEqualAtLeast(10)
return this
}
})
}
})
return this
}
我从赛普拉斯收到一条消息:
CypressError: cy.then() failed because you are mixing up async and sync code.
In your callback function you invoked 1 or more cy commands but then returned a synchronous value.
Cypress commands are asynchronous and it doesn't make sense to queue cy commands and yet return a synchronous value.
You likely forgot to properly chain the cy commands using another cy.then().
The value you synchronously returned was: '{}'
我从以下位置阅读了一份文档:
https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell
但我不确定它应该如何编写才能正常工作。在这个方法之后,我想同步调用其他的。
有人知道我该怎么做吗?
【问题讨论】:
标签: javascript html automated-tests cypress