[英]array sort method doesn't work outside cypress each but works inside
Here is the program piece where you can see that:这是您可以看到的程序片段:
The problem is that I like to sort this likes array outside cy.get(..).each() as next instruction not inside.问题是我喜欢在 cy.get(..).each() 之外对这个 like 数组进行排序,因为下一条指令不在里面。 But that is not working and I have no clue as to why.
但这不起作用,我不知道为什么。 Please could you help in here ?
请问你能帮忙吗?
![]()
var likes = [] cy.get('.blogs').each(($el, index) => { const bcy = cy.wrap($el) bcy.get('#viewBlog').click() const like = Math.floor(Math.random() * 10) likes[index] = like for(let i=like;i--; ) bcy.get('.blogsDetail').eq(index).contains('likes').click() likes.sort((a, b) => b - a) })<\/code><\/pre>"
Cypress commands are asynchronous.赛普拉斯命令是异步的。 To sort the array after the
each<\/code> command, you have to use a
then<\/code> callback:
要在
each<\/code>命令之后对数组进行排序,您必须使用
then<\/code>回调:
var likes = []
cy.get('.blogs').each(($el, index) => {
const bcy = cy.wrap($el)
bcy.get('#viewBlog').click()
const like = Math.floor(Math.random() * 10)
likes[index] = like
for(let i=like;i--; )
bcy.get('.blogsDetail').eq(index).contains('likes').click()
}).then(() => {
likes.sort((a, b) => b - a)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.