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

test: Resolve Cypress Flaky fixes #3034

Merged
merged 89 commits into from
Nov 27, 2024

Conversation

josh-bagwell
Copy link
Contributor

@josh-bagwell josh-bagwell commented Nov 5, 2024

Summary

Fixes: #2900

This is adding fixes for the Cypress flaky specs that were caused from the Webpack Upgrade.

This is addressing Flaky results for Cypress. A test is considered to be flaky when it can pass and fail across multiple retry attempts without any code changes. For example, a test is executed and fails, then the test is executed again, without any change to the code, but this time it passes. See more about Flaky here.

A Flaky result only happens in the CI and not in local since running Cypress locally only gives pass or fail results.

We had recently switched from E2E tests (end-to-end) to Component tests when upgrading Storybook and this had created flaky results on some of our components. We think this may be due to the nature of the Component runner as it is so much quicker than E2E. Due to it's nature of being much quicker, it resulted in flaky results due to our components not being to move as quick as the component runner. There may be times where the Component runner would move quicker than an item being focused in a menu or an item switching focus from one item to the next.

To address the Flaky issues, there have been updates made to some Component Specs:

  • Be more explicit with contexts (making sure that each line could be something that a user would do)
  • Rely on the use of findByRole() instead of using get(). This allows us to be more specific about what element it is grabbing
  • Removing deeply nested contexts and moving out to it's own context. This way we are not using more beforeEach than is needed and improves legibility.

Release Category

Test


Where Should the Reviewer Start?

/cypress/component

Copy link

cypress bot commented Nov 5, 2024

Workday/canvas-kit    Run #8110

Run Properties:  status check passed Passed #8110  •  git commit 06ef4e03e8 ℹ️: Merge a5a71136485ad968f67018392c339649c640cc8d into ccd5c9217de81d6253c83f102717...
Project Workday/canvas-kit
Branch Review fix-flaky-24-11
Run status status check passed Passed #8110
Run duration 02m 41s
Commit git commit 06ef4e03e8 ℹ️: Merge a5a71136485ad968f67018392c339649c640cc8d into ccd5c9217de81d6253c83f102717...
Committer Josh
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 21
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 923
View all changes introduced in this branch ↗︎
UI Coverage  21.26%
  Untested elements 1520  
  Tested elements 408  
Accessibility  99.14%
  Failed rules  6 critical   5 serious   0 moderate   2 minor
  Failed elements 162  

@josh-bagwell josh-bagwell added ready for review Code is ready for review review in progress Code is currently under review labels Nov 25, 2024
@mannycarrera4 mannycarrera4 changed the title fix: Cypress Flaky fixes test: Resolve Cypress Flaky fixes Nov 26, 2024

context('when the dropdown menu is toggled with a keypress', () => {
it('should set focus to the first menu item', () => {
// cy.findByRole('menuitem', {name: 'Second Link'}).focus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// cy.findByRole('menuitem', {name: 'Second Link'}).focus();

});
it('should toggle focus to the second menu item on down keypress', () => {
cy.findByRole('menuitem', {name: 'Third Link'}).should('exist');
// cy.findByRole('menuitem', {name: 'Second Link'}).should('have.focus');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// cy.findByRole('menuitem', {name: 'Second Link'}).should('have.focus');

cy.focused().realType('{downarrow}');
cy.focused().realType('{downarrow}');
cy.focused().realType('{downarrow}');
cy.get('[role="menuitem"]').first().should('contain', 'Second Link');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.get('[role="menuitem"]').first().should('contain', 'Second Link');
cy.findByRole('menuitem').first().should('contain', 'Second Link');

@@ -170,40 +167,44 @@ describe('Menu', () => {
});

it.skip('should focus on the third item', () => {
cy.findByRole('menuitem', {name: 'Third Item'}).should('have.focus');
cy.get('[role="menuitem"]').should('contains', 'Third Item');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.get('[role="menuitem"]').should('contains', 'Third Item');
cy.findByRole('menuitem').should('contains', 'Third Item');

'have.attr',
'aria-labelledby'
);
cy.get('[role="dialog"]').should('exist');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think get makes a difference here, can we change these back to findByRole?

@@ -702,7 +702,7 @@ context(`given the 'Iframe Test' story is rendered`, () => {
});

it('should focus on the close button', () => {
cy.findByRole('button', {name: 'Close'}).should('have.focus');
cy.get('button[aria-label="Close"]').should('have.focus');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@josh-bagwell josh-bagwell added automerge and removed ready for review Code is ready for review review in progress Code is currently under review labels Nov 27, 2024
@alanbsmith alanbsmith merged commit 89347dd into Workday:master Nov 27, 2024
28 checks passed
@josh-bagwell
Copy link
Contributor Author

josh-bagwell commented Nov 27, 2024

Merging this PR now and will update with Manny suggestions at a later date

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

Successfully merging this pull request may close these issues.

Cypress Flaky tests need to be updated
3 participants