cypress-wait-until
cypress-wait-until copied to clipboard
How do I log using waitUntil() to troubleshoot issues?
Hi,
I'm hoping you can help.
I have used waitUntil() successfully with practically the same block of code as below, but this always fails:
cy.get('@id').then(id => {
cy.get('@expectedFileData').then(expectedFileData => {
cy.waitUntil(() => cy.task('queryDatabase', {
query: `SELECT rbm.*
FROM rx_bx_mx rbm
INNER JOIN rx_sx rs ON rbm.rx_sx_id = rs.id
INNER JOIN rx_sx_ix_fx rsif ON rs.rx_sx_ix_fx_id = rsif.id
INNER JOIN rx_sx_ix_fx_bx rsifb ON rsif.rx_sx_ix_fx_bx_id = rsifb.id
WHERE rsifb.uuid = '${id}'`, databaseName: 'rx'}).then((databaseResponse: any) => {
const expectedRecordCount = expectedFileData.length + expectedFileData.filter(element => /\d+$/.test(element)).length
return databaseResponse.length == expectedRecordCount ? databaseResponse : false
}), { timeout: constants.timeouts.threeMinutes, interval: constants.intervals.fifteenSeconds, errorMsg: 'Failed on step [censored]. databaseResponse.length never equalled expectedRecordCount.' }).then(databaseResponse => {
cy.wrap(databaseResponse).as('databaseData')
})
})
})
In the code that works, there's no expectedRecordCount
and all I'm doing is: return databaseResponse.length == expectedFileData.length ? databaseResponse : false
I could delve into the context of what I'm doing here but essentially what I need to do is log out the result of the database call/the counts for each attempt to figure out why it's always failing.
Edit: the database query works in MySQL Workbench and gives me the expected number of records.
I have not been able to use cy.log()
in my task's 'then' block due to this error ("cy.then() failed because you are mixing up async and sync code...") and console.log (inserted before the return
statement)...
console.log('!!!!! expectedRecordCount: ' + expectedRecordCount)
console.log('!!!!! databaseResponse.length: ' + databaseResponse.length)
...doesn't output anything.
I have so far not been able to correctly understand how I implement logging with your plugin to achieve this.