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

495
Views
Comparar el elemento de texto con el signo "%" como un número y ver si un número es mayor que 0 no funciona
describe('dropdown select', () => { it('open dropdown and check if 24hr rate is positive', () => { Cypress.on('uncaught:exception', (err, runnable) => {return false}) //it was throwing expections for me for unknown reason so I had to ignore it cy.visit('link') cy.get('[data-cy=accept-btn]').click() cy.get('#currency-select').should('be.visible').click() cy.get('[class=" css-zkvt1b-menu"]').should('be.visible').contains('EUR').click() cy.get('[class="Yq Zq"]').each((el) => { const text = el.text(); expect(text).to.be.greaterThan(0); }) }); })

Recibo un error al verificar que el número es mayor que 0. Agrego una imagen del error a continuación: NOTA: los números son diferentes en las capturas de pantalla porque se tomaron con pocos minutos de diferencia.

ingrese la descripción de la imagen aquí

código cromo:

ingrese la descripción de la imagen aquí

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

0

Debe extraer el número y eliminar las cadenas adicionales y luego convertirlo en un número y luego aplicar aserciones.

 cy.visit('https://spectrocoin.com/en/bitcoin-price-rates.html') Cypress.on('uncaught:exception', (err, runnable) => { return false }) cy.get('[data-cy=accept-btn]').click() cy.get('#currency-select').should('be.visible').click() cy.get('[class=" css-zkvt1b-menu"]') .should('be.visible') .contains('EUR') .click() cy.get('[data-cy="rates"] tr').each((el) => { cy.wrap(el).within(() => { cy.get('td') .eq(2) .invoke('text') .then((text) => { const last24HourVal = +text.slice(13, -1) expect(last24HourVal).to.be.greaterThan(0) }) }) })

La prueba anterior fallará para los valores que son menores que 0. Para verificar si el número puede ser positivo o negativo, debe usar una declaración condicional y verificar que el valor sea mayor o menor que 0 y luego aplicar la afirmación. Algo como:

 cy.visit('https://spectrocoin.com/en/bitcoin-price-rates.html') Cypress.on('uncaught:exception', (err, runnable) => { return false }) cy.get('[data-cy=accept-btn]').click() cy.get('#currency-select').should('be.visible').click() cy.get('[class=" css-zkvt1b-menu"]') .should('be.visible') .contains('EUR') .click() cy.get('[data-cy="rates"] tr').each((el) => { cy.wrap(el).within(() => { cy.get('td') .eq(2) .invoke('text') .then((text) => { const last24HourVal = +text.slice(13, -1) if (last24HourVal > 0) { expect(last24HourVal).to.be.greaterThan(0) } else { expect(last24HourVal).to.be.lessThan(0) } }) }) })
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!