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

304
Views
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 answers
Answer question

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 Report

0

fix code as below :D

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

I hope you find an answer!

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!