I am currently working on a Cypress/TypeScript test case that involves editing the selected value of a dropdown.
While chaining promises and utilizing Page Objects, I have encountered two main issues:
- The assertion meant to be evaluated at the end is executed prematurely.
- This premature execution leads to a failed assertion, yet the test still passes inexplicably.
screenshot: cl.ly/e4cb6837377c
spec
it.only('C180: Change Tracking type: Important tasks => Time measurement', function () {
const timeMeasurement = 'Time measurement'
billing.currentTrackingType().then((trackingType) => {
if(trackingType == timeMeasurement)
this.skip()
billing.changeTrackingType(1).then(() => {
billing.currentTrackingType().then(($trackingType) => {
expect($trackingType).to.contain(timeMeasurement)
})
})
})
})
Page object:
currentTrackingType() {
return new Promise((resolve, reject) => {
const timer = Cypress.$(this.elements.timer)
resolve(timer.length? 'Time measurement':'Important tasks')
})
}
changeTrackingType(index: any){
const settingsChanged = 'Timesheet settings has been changed'
return new Promise((resolve, reject) => {
cy.get(this.elements.trackingType).select(index.toString())
cy.get(this.elements.save).eq(3).click()
resolve()
})
}
}