Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!