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

Cypress moves onto next line before completing previous command #29780

Open
mmestas opened this issue Jul 1, 2024 · 1 comment
Open

Cypress moves onto next line before completing previous command #29780

mmestas opened this issue Jul 1, 2024 · 1 comment
Labels
stage: needs information Not enough info to reproduce the issue

Comments

@mmestas
Copy link

mmestas commented Jul 1, 2024

Current behavior

I'm having the exact same issue reported back in 2019 with issue #5480
#5480

When running a large test that checks many form fields, cypress errors at different points due to not completing the previous command before running the next command. If I break this test into smaller sections, it seems to work fine and I get no errors, but when running the test over the entire form, each time I get an error in a different spot.

The last time it failed, it was supposed to type an invalid value of "100" before checking to see if there was an error message for that field. Cypress failed stating, "expected [data-cy="alt_chan_outgain_errors_0-1"] to exist in the DOM" however, on inspection, it had NOT typed 100 before proceeding to that next check. On other runs, it got past this check and failed in a similar fashion on another input. I originally had the commands chained together (ex. cy.get('[data-cy="alt_chan_outgain_'+idx+'-'+gain+'"]').clear().type('100'); )and separated them to see if that would fix it, and it helped slightly, but I'm still getting errors.

Another instance of it failing while running the test was it didn't clear before typing the new value. The previous value was 10 and should clear and then type 9. This worked as it looped through several inputs just fine, but randomly failed on one. Instead of 10 as the value, it was 910. The value never cleared even though the command "clear()" ran.
Screenshot 2024-07-01 at 9 10 13 AM
Screenshot 2024-07-01 at 9 10 32 AM

Again, if I just run the test on this one section at a time, it passes. It seems that it gets overloaded when running the full form with the .each loops.

Desired behavior

Finish the command fully before checking the next command.

Test code to reproduce

cy.get('[data-cy="device_alternate_gains"] > .nav-item').each(($tab, idx) => {
			cy.get('[data-cy="alt_chan'+idx+'"]').click();
			cy.get('[data-cy="alt_chan_hw_selector'+idx+'"]').should('exist');

			let gainArr = [1,2,3];
			gainArr.forEach(gain => {
				cy.get('[data-cy="alt_chan_mic_'+idx+'-'+gain+'"]').should('be.visible').check();

				cy.get('[data-cy="alt_chan_ingain_'+idx+'-'+gain+'"]').invoke('val').then(val => {
					let originalVal = parseInt(val as unknown as string, 10);
					let numToUse = originalVal === 10 ? '9' : '10';
					cy.get('[data-cy="alt_chan_ingain_'+idx+'-'+gain+'"]').clear();
					cy.get('[data-cy="alt_chan_ingain_'+idx+'-'+gain+'"]').type('-10');
					cy.get('[data-cy="alt_chan_ingain_errors_'+idx+'-'+gain+'"]').should('exist').should('not.be.empty');
					cy.get('[data-cy="fdh_save"]').should('exist').should('be.disabled');
					cy.get('[data-cy="fdh_unsaved_msg"]').should('exist').contains('Form has invalid values');
					cy.get('[data-cy="alt_chan_ingain_'+idx+'-'+gain+'"]').clear();
					cy.get('[data-cy="alt_chan_ingain_'+idx+'-'+gain+'"]').type(numToUse);
					cy.get('[data-cy="alt_chan_ingain_errors_'+idx+'-'+gain+'"]').should('not.exist')
				});
				cy.get('[data-cy="alt_chan_outgain_'+idx+'-'+gain+'"]').invoke('val').then(val => {
					let originalVal = parseInt(val as unknown as string, 10);
					let numToUse = originalVal === 10 ? '9' : '10';
					cy.get('[data-cy="alt_chan_outgain_'+idx+'-'+gain+'"]').clear();
					cy.get('[data-cy="alt_chan_outgain_'+idx+'-'+gain+'"]').type('100');
					cy.get('[data-cy="alt_chan_outgain_errors_'+idx+'-'+gain+'"]').should('exist').should('not.be.empty');
					cy.get('[data-cy="fdh_save"]').should('exist').should('be.disabled');
					cy.get('[data-cy="fdh_unsaved_msg"]').should('exist').contains('Form has invalid values');
					cy.get('[data-cy="alt_chan_outgain_'+idx+'-'+gain+'"]').clear();
					cy.get('[data-cy="alt_chan_outgain_'+idx+'-'+gain+'"]').type(numToUse);
					cy.get('[data-cy="alt_chan_outgain_errors_'+idx+'-'+gain+'"]').should('not.exist')
				});
				
			});

		});

Cypress Version

13.9.0

Node version

18.15.0

Operating System

Mac OS 14.3.1

Debug Logs

No response

Other

Using this with Angular 17.2.3

@jennifer-shehane
Copy link
Member

@mmestas Can you provide an example that we can run to see the issue? It will be impossible to address without this, as the issue is likely dependent on how the form functions.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants