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

155
Vistas
How to get the value from other method/function in JavaScript

I am new to Cypress and JavaScript, Please help me with this query to understand more

I have to automate a website using cypress to validate the EMI value.

Below is my .js code where I need to implement the EMI calculator logic and need to pass it to another method ('it' block in cypress). 'it' block will get the value from the website and should validate with the EMI logic which I return in code EMILogic() method.

EMILogic() will return a value (emi) and I am passing this value in line cy.get('#emi').should('have.text', EMIdata.emi) but while executing the code I am getting assertion error in cypress as Timed out retrying after 4000ms: expected '<span#emi>' to have text undefined, but the text was '925.11'

describe('EMI Calculation', function () {

 class abc{
 EMILogic() {

    const amount = 20000;
    const rate = 5;
    const month = 2;
let emi;
rate = rate/(12*100);
period = period*12;

emi = (amount*rate*Math.pow(1+rate, month))/(Math.pow(1+rate, month)-1);
return emi

   }
   }

Below is the code where I need to pass the value of emi from above class

    it('EMI calculator', function () {
    const EMIdata = new abc();

    cy.visit('emi-calculator.html')
    cy.get('.MR15').click()
    cy.get('#emi').should('have.text', EMIdata.emi)

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

0

Problem:

const EMIdata = new abc();

This line of code means EMIdata is an object of class abc. there is no member variable named emi on class abc. hence you are getting an undefined when using EMIdata.emi.

Solution:

As your member function EMILogic returns the emi value. Instead of EMIdata.emi you can call EMILogic using EMIdata.EMILogic() inside your should function.

cy.get('#emi').should('have.text', EMIdata.EMILogic())
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