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

306
Vistas
function returns [object object] instead of string Cypress

Want to have single function to get the dynamic text value from application.

getStartDate() function return as [object object] when calling from different function getDate() whereas cy.log(mon...) from getStartDate() gives the correct date in the format of string. Also cy.wrap(mom...) wrap a correct date in string format

   getStartDate(){
         return cy.get('[data-placeholder="Select time range (from)"]').invoke('val').then($da=>{
              cy.log(moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss')+"------------------")  //  returns "03.01.2022 11:10:00"
               return (cy.wrap(moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss').valueOf())) ;Text   // return "03.01.2022 11:10:00"
               
            })
        }

Calling function:

     getDate(){
        cy.log(this.getStartDate().toString()+"------------") // returns [object object]
        }

Kindly let me know how to get the value from getStartDate() by calling through out the application

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

0

cy.wrap is used to create a cypress chainer object. Moreover, you are returning cy.get(...) from the function, which is an object. You sould try to use Promises:

async getStartDate() {
         const $da = await cy.get('[data-placeholder="Select time range (from)"]').invoke('val');
         cy.log(moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss')+"------------------")  //  returns "03.01.2022 11:10:00"
         return moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss');
}

And use it like this:

getStartDate().then((startDate) => cy.log(startDate));
about 4 years ago · Juan Pablo Isaza Denunciar

0

fix code as below :D

cy.log(this.getStartDate().toString(),"------------")

I hope you find an answer!

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