如何多次重复赛普拉斯的测试?

How to repeat a test in Cypress multiple times?

我的一个 Cypress 测试中有以下代码部分:

cy.window()
  .its('store')
  .invoke('getState')
  .then((state) => {
    expect(state.app.gameStarted).to.equal(true)
    expect(state.app.noteButtonValues).to.have.lengthOf(4);
    expect(state.app.noteButtonValues).to.include(state.app.correctAnswer)
    cy.get("button").contains(state.app.correctAnswer).click()

    cy.window()
    .its('store')
    .invoke('getState')
    .then((state) => {  
        expect(state.app.correctAnswered).to.equal(1)
        expect(state.app.totalAnswered).to.equal(1)
    })   
  })
})

我正在测试当用户单击按钮时,redux 状态也会更新。现在假设我想重复此部分 100 次左右的点击。怎么可能?

将它包装在 for 循环中不起作用,例如:

for (let i = 0; i < 100; i = i++) {
    cy.window()
    .its("store")
    .invoke("getState")
    .then((state) => {
        expect(state.app.gameStarted).to.equal(true);
        expect(state.app.noteButtonValues).to.have.lengthOf(4);
        expect(state.app.noteButtonValues).to.include(state.app.correctAnswer);
        cy.get("button").contains(state.app.correctAnswer).click();

        cy.window()
        .its("store")
        .invoke("getState")
        .then((state) => {
            expect(state.app.correctAnswered).to.equal(1);
            expect(state.app.totalAnswered).to.equal(1);
        });
    });
}

使用lodash方法Cypress._.times()

示例:

Cypress._.times(100, (k) => {
  it(`typing hello ${k + 1} / 100`, () => {
    cy.log(k)
  })
})