Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Cypress - Create group base on JSON file

I wanna create 2 groups (Rose and Sunflower) in App based on the JSON file but the loop only runs 1 time

Here's my code

            cy
            .fixture('create-delete-group')
            .then( (gr) => {
                for (let i = 0; i < gr.length; i++) {
                    cy.window().then((win) => {
                        cy.stub(win, 'prompt').returns(gr[i].groupNames)
                        groupManaPage.elements.btnCreateGroup().click()
                    })
                    cy.on('window:alert', (str) => {
                        expect(str).to.equal('New group has been created successful!')
                    })

                }

            })

Here's json file

[
  {
    "groupNames": "Rose",
    "members": [
      "torido11",
      "torido12"
    ]
  },
  {
    "groupNames": "Sunflower",
    "members": "torido13"
  }
]
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to .restore() the first stub in order to use it again, other than that the code is fine.

cy.fixture('create-delete-group').then(gr => {

  for (let i = 0; i < gr.length; i++) {
    cy.window().then((win) => {
      const stub = cy.stub(win, 'prompt')      // save stub reference
        .returns(gr[i].groupNames)
      groupManaPage.elements.btnCreateGroup().click()

      cy.on('window:alert', (str) => {
        expect(str).to.equal('New group has been created successful!')

        stub.restore()                         // remove stub
      })
    
    })
  }
})
almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!