Cypress IO- Writing a For Loop

不问归期 提交于 2020-06-24 22:25:09

问题


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

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?


回答1:


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()
})


来源:https://stackoverflow.com/questions/52212868/cypress-io-writing-a-for-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!