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
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));
fix code as below :D
cy.log(this.getStartDate().toString(),"------------")
I hope you find an answer!