Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda