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

506
Vistas
Comparing text element with "%" sign like a number and seeing if a number is greaterThan 0 does not work
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);
    })

  });
})  

I am getting error checking of the number is greaterThan 0. Adding a picture of the error below: NOTE: the numbers are different in screenshots because they were taken few minutes apart.

enter image description here

Chrome code:

enter image description here

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

0

You have to extract the number and remove the extra strings and then convert it into a number and then apply assertions.

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

The above test will fail for values which are less than 0. To check whether the number can be positive or negative you have to use a conditional statement and check for the value to be greater or less than 0 and then apply assertion. Something like:

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