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

214
Views
¿Cómo establecer múltiples valores en una sola variable en un archivo .json usando ciprés?

Aquí está mi código para escribir valores obtenidos en el archivo .json.

 cy.readFile(filename).then((product) => { for (var i = 1; i < lens; i++) { cy.xpath('/html/body/app-root/div/mat-sidenav-container/mat-sidenav-content/app-configurable-product/div[1]/mat-table/mat-row[' + i + ']/mat-cell[2]').then((txt) => { var namee = txt.text() cy.log(namee) product.product_name = namee cy.writeFile(filename, product, {flag: 'a+'}) }) } })

Quiero obtener datos en el siguiente formato .json.

{
"product_name": [" Camiseta de ajuste estándar Jam & Honey para niña ", " Sudadera con capucha para niños ", " Camiseta sin mangas para mujer "]
}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Tal vez use each en lugar de for loop

 cy.readFile(filename).then((product) => { if (!product.product_name) product.product_name = [] // initial cy.xpath('/html/body/app-root/div/mat-sidenav-container/mat-sidenav-content/app-configurable-product/div[1]/mat-table/mat-row') .each($row => { cy.wrap($row).find('mat-cell').eq(2).invoke('text') .then(text => { product.product_name.push(text) }) }) .then(() => { cy.writeFile(filename, product) }) })
about 4 years ago · Juan Pablo Isaza Report

0

Puede seleccionar varias filas y convertirlas en una matriz de textos

 cy.xpath('/html/body/app-root/div/mat-sidenav-container/mat-sidenav-content/app-configurable-product/div[1]/mat-table/mat-row') .find('mat-cell').eq(2) .then($cells => { const texts = [...$cells].map(cell => cell.innerText) // array of texts cy.readFile(filename).then((product) => { product.product_name = texts cy.writeFile(filename, product) }) })
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!