赛普拉斯IO-编写For循环 [英] Cypress IO- Writing a For Loop

查看:89
本文介绍了赛普拉斯IO-编写For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有15个按钮。我需要测试每个按钮。

I have 15 buttons on a page. I need to test each button.

我尝试了一个简单的for循环,例如

I tried a simple for loop, like

for (var i = 1; i < 15; i++) {

   cy.get("[=buttonid=" + i + "]").click()
}

但是赛普拉斯不喜欢这样。我该如何在赛普拉斯中编写循环?

But Cypress didn't like this. How would I write for loops in Cypress?

推荐答案

要强制执行任意循环,请使用所需的索引创建一个数组,然后调用 cy.wrap

To force an arbitrary loop, I create an array with the indices I want, and then call cy.wrap

var genArr = Array.from({length:250},(v,k)=>k+1)
cy.wrap(genArr).each((index) => {
    cy.get("#button-" + index).click()
})

这篇关于赛普拉斯IO-编写For循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆