HyeEun
HyeEun

Reputation: 707

How to 'hammer' click in cypress.io?

I am running with Chrome 74 and am wanting to write a test that will 'spam' click a counter.

Is there any way to write it so it will click x times instead of writing this over and over:

cy.get('[data-cy=click-up]').click()

I asked in the Cypress Gitter and someone had responded with:

Providing that your selector matches n+ Dom elements, its going to click all of em

cy.get(selector).click({multiple: true})

But this does not work in my problem.

If I could I'd share direct code but I am under an NDA.

Solution

So, I took jon's comment and yes a for loop works to re-create that 'spam' click.

Example:

describe('increase the counter', () => {
  it('spam click by 10', () => {
    for(let n = 0; n < 10; n ++){
      cy.get('[data-cy=click-up]').click()
    }
  })
})

Upvotes: 0

Views: 1304

Answers (1)

HyeEun
HyeEun

Reputation: 707

Solution

So, I took jon's comment and yes a for loop works to re-create that 'spam' click.

Example:

describe('increase the counter', () => {
  it('spam click by 10', () => {
    for(let n = 0; n < 10; n ++){
      cy.get('[data-cy=click-up]').click()
    }
  })
})

Upvotes: 2

Related Questions