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

201
Views
Pasar parámetros con valores de coma (formato decimal europeo)

He escrito una función reutilizable en Cypress:

 fill_prices_ht_nt(until, AP, GP, AP_NT, new_bonus){ this.add_range().click({force:true}) this.range_until().type(until) this.ap().type(AP) this.gp().type(GP) this.ap_nt().type(AP_NT) this.new_bonus().type(new_bonus)

Ahora quiero usar esa función para escribir valores, pero desafortunadamente necesito escribir valores decimales en formato europeo (con coma en lugar de puntos), como por ejemplo "9,35" o "6,47"

 pmmt.fill_prices_ht_nt(99999, 10, 9,35, 6,47, 100)

Por supuesto, esto no funciona ya que Cypress/JS trata cada coma como un separador.

¿Hay una solución algo fácil para este problema? De lo contrario, tendré que volcar la función reutilizable y codificar los valores.

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

0

Puede proporcionar los números como cadenas, así:

 pmmt.fill_prices_ht_nt("99999", "10", "9,35", "6,47", "100")

Luego escribe una función de utilidad para convertir esas cadenas en números:

 function toNumber(val) { if (typeof val !== "string") { return val; } return +val.replace(/,/g, "."); }

(Unary + es solo una forma de hacer una conversión de cadena a número, proporciono una lista con ventajas y constantes en esta respuesta ).

Y úsalo en tu función:

 fill_prices_ht_nt(until, AP, GP, AP_NT, new_bonus) { until = toNumber(until); AP = toNumber(AP); GP = toNumber(GP); AP_NT = toNumber(AP_NT); new_bonus = toNumber(new_bonus); this.add_range().click({force:true}); this.range_until().type(until); this.ap().type(AP); this.gp().type(GP); this.ap_nt().type(AP_NT); this.new_bonus().type(new_bonus); }

Si no le importa usar una matriz temporal, puede usar la desestructuración para hacer las conversiones todo en uno:

 function toNumberList(...vals) { return vals.map(toNumber); }

Luego usándolo:

 fill_prices_ht_nt(until, AP, GP, AP_NT, new_bonus) { [until, AP, GP, AP_NT, new_bonus] = toNumberList(until, AP, GP, AP_NT, new_bonus); this.add_range().click({force:true}); this.range_until().type(until); this.ap().type(AP); this.gp().type(GP); this.ap_nt().type(AP_NT); this.new_bonus().type(new_bonus); }

Eso supone un entorno ES2015+ (porque usa desestructuración).

about 4 years ago · Juan Pablo Isaza Report

0

¿Qué tal si usas pmmt.fill_prices_ht_nt con todos los números como cadenas?

 pmmt.fill_prices_ht_nt('99999', '10', '9,35', '6,47', '100')

Porque cuando veo el tipo de ciprés, en la sintaxis dice, el type acepta estos dos formatos:

 .type(text) .type(text, options)
about 4 years ago · Juan Pablo Isaza Report

0

Aquí hay una opción más, usando toLocaleString()

 fill_prices_ht_nt(until, AP, GP, AP_NT, new_bonus) { this.add_range().click({force:true}) this.range_until().type(until) this.ap().type(AP.toLocaleString('de-DE')) this.gp().type(GP.toLocaleString('de-DE')) // AP.toLocaleString('de-DE') = 9,35 this.ap_nt().type(AP_NT.toLocaleString('de-DE')) this.new_bonus().type(new_bonus.toLocaleString('de-DE'))

En la prueba, pase con decimal y se convertirá a medida que .type()

 pmmt.fill_prices_ht_nt(99999, 10, 9.35, 6.47, 100)

O bien, puede agregar un método para establecer el formato si tiene otras configuraciones regionales para manejar

 set_number_format(number_format) { this.number_format = number_format } fill_prices_ht_nt(until, AP, GP, AP_NT, new_bonus) { this.add_range().click({force:true}) this.range_until().type(until) this.ap().type(AP.toLocaleString(this.number_format)) this.gp().type(GP.toLocaleString(this.number_format)) this.ap_nt().type(AP_NT.toLocaleString(this.number_format)) this.new_bonus().type(new_bonus.toLocaleString(this.number_format))

En la prueba,

 pmmt.set_number_format('de-DE') pmmt.fill_prices_ht_nt(99999, 10, 9.35, 6.47, 100) ... pmmt.set_number_format('en-IN') pmmt.fill_prices_ht_nt(99999, 10, 9.35, 6.47, 100)
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!