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

137
Vistas
How to reference a JS array value and interpolate into JSON

Forgive a beginners question. I am learning JS to help with my Cypress automation skills - this may be a bad solution and I'm happy to learn a better way.

Given a json file versions.json

{
"cypress": "1.1.0",
"playwright": "1.1.0",
"seleniumJava": "1.1.0",
"geb": "1.1.0",
"postman": "1.1.0"
}

I need to iterate through each url, visit the relevant release page and get the latest tool version.

My specific question is, how do I pass the tool from the tools array so I can interpolate it into here:

let version = data.{tool}version;...to allow cypress to know which tool version to get?

   //env vars to get the relevant urls here
    const urls = [cypressBaseUrl, playwrightBaseUrl, seleniumJavaBaseUrl, gebBaseUrl, postmanBaseUrl]
    const tools = ["cypress", "playwright", "seleniumJava", "geb", "postman"]

    it("Gets the latest release versions", () => {
        urls.forEach(function (url) {
            tools.forEach(function (tool) {
                cy.readFile('cypress/fixtures/versions.json').then((data) => {
                    let version = data.{tool}version; //how do I pass each tool here?
                    let updated
                    cy.visit(url)
                    cy.get('div.nuxt-content')//refactor to work for all tools
                        .first('h2')
                        .then(txt => {
                         const versionTxt = txt.find("h2").text()//get latest version
                    versionTxt = version 
                    cy.writeFile('cypress/fixtures/versions.json', {
                                tool: versionTxt
                            })
                        })
                })
            })
        })
    })
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

if you're trying to access version values from versions.json and tools contains the keys in versions.json, you can use array notation to pull out the values:

tools.forEach(function (tool) {
  cy.readFile('cypress/fixtures/versions.json').then((data) => {
    let version = data[tool] //will hold whatever value `versions.json` has for the given `tool` key

    cy.visit(url)
    cy.get('div.nuxt-content')
      .first('h2')
      .then(txt => {
        const versionTxt = txt.find("h2").text() //get latest version
        versionTxt = version 
        cy.writeFile('cypress/fixtures/versions.json', {
          tool: versionTxt
        })
      })
  })
})
// ...

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