Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

The .its('length').then() pattern was causing flaky test failures when DOM elements change. This PR refactors all occurrences to assign length values to regular JavaScript variables before proceeding with test logic.

Changes

Refactored 23 occurrences across 5 test files to use variable assignment pattern:

Before:

navigationMenuPage.getMenuItems().its('length').then(initialCount => {
  // use initialCount
});

After:

let initialCount: number;
navigationMenuPage.getMenuItems().its('length').then((length) => {
  initialCount = length;
});

cy.then(() => {
  // use initialCount
});

Files Modified

  • cypress/e2e/MyEforms.page.ts - clearEFormTable method
  • cypress/e2e/c/navigation-menu.create-item.spec.cy.ts - 9 occurrences
  • cypress/e2e/c/navigation-menu.edit-item.spec.cy.ts - 5 occurrences
  • cypress/e2e/c/navigation-menu.delete-item.spec.cy.ts - 5 occurrences
  • cypress/e2e/c/navigation-menu.drag-item.spec.cy.ts - 3 occurrences

This approach assigns values to variables before proceeding with test logic, providing clearer separation between value retrieval and test execution for more predictable and reliable test behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>avoid using .then in cypress tests, assing values to variables and then proceed</issue_title>
<issue_description>The current style of getting the number of items in a page with the same domId is not working correctly/flaky when using the style of eg:

navigationMenuPage.getMenuItems().its('length').then(initialCount => {

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Refactor Cypress tests to avoid using .then method Replace flaky .its('length').then() pattern with Cypress aliases Nov 11, 2025
Copilot AI requested a review from renemadsen November 11, 2025 12:24
Copilot finished work on behalf of renemadsen November 11, 2025 12:24
@renemadsen
Copy link
Member

@copilot just moving the .then to next line does not solve it. It should be
const foo.bar = lenght;
do the checks against the foo.bar.

Copy link
Contributor Author

Copilot AI commented Nov 11, 2025

@copilot just moving the .then to next line does not solve it. It should be
const foo.bar = lenght;
do the checks against the foo.bar.

Fixed in commit 562b17d. The tests now assign values to variables before proceeding with the test logic.

Pattern changed from:

navigationMenuPage.getMenuItems().its('length').as('initialCount');
cy.get('@initialCount').then((initialCount) => { ... });

To:

let initialCount: number;
navigationMenuPage.getMenuItems().its('length').then((length) => {
  initialCount = length;
});

cy.then(() => {
  // use initialCount
});

All 23 occurrences across 5 test files have been refactored to use this pattern.

Copilot AI changed the title Replace flaky .its('length').then() pattern with Cypress aliases Refactor Cypress tests to assign values to variables before proceeding Nov 11, 2025
Copilot finished work on behalf of renemadsen November 11, 2025 13:42
@renemadsen renemadsen closed this Nov 16, 2025
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

Successfully merging this pull request may close these issues.

avoid using .then in cypress tests, assing values to variables and then proceed

3 participants