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

135
Visualizações
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 à 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