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

144
Vistas
How to iterate array with vivewports with it tests and beforeeach

I run into issue with viewport issue and I didn't find the solution yet.

describe('Tests', function () {
beforeEach(function () {
});

viewports.forEach((viewport) => {
    it.only(`Test: ${viewport}`, function () {
        cy.viewportAdjust(viewport);
    })})})

I used cy.viewportAdjust(viewport);in my test and it works, however I wish to move cy.viewportAdjust(viewport); to beforeEach section but for tests it uses last value of viewportsArray

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

I'm not entirely sure what cy.viewportAdjust() does, as that looks to be a custom function. If the function simply calls cy.viewport() or updates the viewport, the following will work. Additionally, with not knowing what the values in viewport are, I can't give an exact complete answer, but the general idea is that you can pass in your viewportWidth or viewportHeight in the it() block.

viewports.forEach((viewport) => {
    it.only(`Test: ${viewport}`, { viewportWidth: viewport }, function () {
        cy.viewportAdjust(viewport);
    })
})
about 4 years ago · Santiago Gelvez Denunciar

0

Im going to answer this question exactly how you asked. But I would not suggest doing it this way though without seeing everything that you are trying to do I don't have 100% confidence in this statement.

describe('Tests Viewports', () => {
  const viewports = ['iphone-6', 'ipad-2', 'ipad-mini'] //insert viewport you wish to test here
  let x = 0
  beforeEach( () => {
    cy.viewport(viewports[x])
    //Do a thing
    x += 1
  })
  viewports.forEach( (viewport) => {
    it(`Tests: ${viewport}`, () => {
      cy.log(viewport)
    })
  })
})

I would instead suggest removing the beforeEach block and putting your code within the it block.

about 4 years ago · Santiago Gelvez 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