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

202
Vistas
Passing parameters with comma values (European decimal format)

I have written a reusable function in 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)

Now I want to use that function to type in values, but unfortunately I need to type in decimal values in European format (with comma instead of periods), like e.g. "9,35" or "6,47"

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

This is of course not working as Cypress/JS treats every comma as a separator.

Is there a somewhat easy workaround to this problem? Otherwise I will have to dump the reusable function and hard-code the values.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can supply the numbers as strings, like this:

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

Then write a utility function to convert those strings to numbers:

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

(Unary + is just one way to do string-to-number conversion, I provide a list with pros and const in this answer.)

And use it in your function:

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);
}

If you don't mind using a temporary array, you can use destructuring to do the conversions all in one:

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

Then using it:

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);
}

That assumes an ES2015+ environment (because it uses destructuring).

about 4 years ago · Juan Pablo Isaza Denunciar

0

How about you just use the pmmt.fill_prices_ht_nt with all numbers as strings.

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

Because when I see the cypress type, in syntax it says, type accepts these two formats:

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

0

Here's one more option, using 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'))

In the test, pass with decimal and it will be converted as you .type()

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

Or, you can add a method to set the format if you have other locale's to handle

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))

In the test,

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