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

136
Views
Cómo hacer referencia a un valor de matriz JS e interpolar en JSON

Perdona una pregunta de principiante. Estoy aprendiendo JS para ayudar con mis habilidades de automatización de Cypress; esta puede ser una mala solución y estoy feliz de aprender una mejor manera.

Dado un archivo json versions.json

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

Necesito iterar a través de cada URL, visitar la página de lanzamiento correspondiente y obtener la última versión de la herramienta.

Mi pregunta específica es, ¿cómo paso la herramienta de la matriz de herramientas para poder interpolarla aquí?

let version = data.{tool}version; ...para permitir que Cypress sepa qué versión de herramienta obtener?

 //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 answers
Answer question

0

si está tratando de acceder a los valores de la versión desde versions.json y las tools contienen las claves en versions.json , puede usar la notación de matriz para extraer los valores:

 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 Report
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!