Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I log using waitUntil() to troubleshoot issues? #484

Open
Ixluxi opened this issue Aug 20, 2024 · 5 comments
Open

How do I log using waitUntil() to troubleshoot issues? #484

Ixluxi opened this issue Aug 20, 2024 · 5 comments

Comments

@Ixluxi
Copy link

Ixluxi commented Aug 20, 2024

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.

@NoriSte
Copy link
Owner

NoriSte commented Aug 20, 2024

I can't look into it now, sorry. I'm also from mobile. Just a question: are you sure the const expectedRecordCount = expectedFileData... line doesn't throw?

@Ixluxi
Copy link
Author

Ixluxi commented Aug 20, 2024

I've realised I can run my task after an arbitrary wait outside of the waitUntil() to check what might be the issue, will try that tomorrow.

@Ixluxi
Copy link
Author

Ixluxi commented Aug 21, 2024

Someone might've split expectedFileData on \n, not \r\n, making each line end with \r, resulting in a count of zero for lines ending with a number... 👀

Aside from the PEBCAK issue, how would I have logged stuff out within my checkFunction?

Thanks

@Ixluxi
Copy link
Author

Ixluxi commented Sep 6, 2024

Friendly bump :)

@NoriSte
Copy link
Owner

NoriSte commented Sep 10, 2024

Sorry for the radio silence, I missed your previous comment 🤗 so the logger option was not enough for your use case??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants