Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda