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

132
Vistas
Cypress - Looping through an array

New to Cypress so sorry if this is a basic question.

I have an app that allows the creation of 'datasets' of varying types. I'm trying to create a method that will create a dataset for each available type displayed within a dropdown.

So, to begin with, I have this method that will create a specific dataset (based on the baseType that's passed in).

   createBasicDatasetAndVerifyCreation(baseType){

    const newDatasetTitle = createDatasetName() //Creating a title
    cy.get(':nth-child(1) > .col-sm-6 > .v-input').type(newDatasetTitle) //Typing the title

    cy.get(':nth-child(2) > .col-lg-4 > .v-input').click() //Trigger the dropdown
    cy.get('[class="v-list v-select-list v-sheet theme--light theme--light"]').then( datasetDropdownList => {
        cy.wait(500)
        cy.wrap(datasetDropdownList).contains(baseType).click()
    })
    
    cy.contains('Save').click()

    cy.get('.v-toolbar__content > .text-none').should('contain', 'Datasets') //Checking user is redirected

    //Checking table to see if it's saved correctly
    cy.get('tbody').contains('tr', newDatasetTitle).then( tableRow => {
        cy.wrap(tableRow).should('contain', newDatasetTitle)
        cy.wrap(tableRow).should('contain', 'Custom')
    })
}

I'm now trying to repeat the above for each item within the datasetDropdownList. So far, I've stored the contents of the dropdown as an array using this function-

function getAvailableDatasets(){
const array = []
    cy.get('[class="v-list v-select-list v-sheet theme--light theme--light"]').each(($option, index )=> {
        array.push(Cypress.$($option).text())
        console.log(array[index]);               
    })
return array}

and implemented it here-

createOneOfEachAvailableDataset(){
    const newDatasetTitle = createDatasetName() //Creating a title
    cy.get(':nth-child(1) > .col-sm-6 > .v-input').type(newDatasetTitle) //Typing the title

    cy.get(':nth-child(2) > .col-lg-4 > .v-input').click() //Trigger the dropdown
    cy.wait(500)

    const arrayOfDatasets = getAvailableDatasets()
   
}

I'm now unsure how to loop through the array, creating a new dataset for each type in the array.

about 4 years ago · Juan Pablo Isaza
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