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

fix: Fixed flaky test 24645 #25786

Merged
merged 17 commits into from
Jul 17, 2024
Merged

fix: Fixed flaky test 24645 #25786

merged 17 commits into from
Jul 17, 2024

Conversation

hjetpoluru
Copy link
Contributor

@hjetpoluru hjetpoluru commented Jul 11, 2024

Description

This PR addresses a flaky test related to "Custom network Popular Networks List delete the Arbitrum network."

I was unable to reproduce the issue locally. However, after analyzing the CI screenshots, I identified the reason for the failure. The screenshot shows the support page appearing after the dropdown menu is displayed.

Screenshot 2024-07-11 at 4 18 01 PM

To resolve this, I have updated the test to click on the Settings using the data-testid attribute.

Open in GitHub Codespaces

Related issues

Fixes: #24645

Manual testing steps

Run locally or using codepsaces
yarn
yarn build:test:mmi
yarn test:e2e:single test/e2e/tests/network/add-custom-network.spec.js --browser=chrome --debug --leave-running

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jul 11, 2024
@danjm
Copy link
Contributor

danjm commented Jul 11, 2024

Why was the support page appearing?

@hjetpoluru
Copy link
Contributor Author

hjetpoluru commented Jul 11, 2024

@danjm After seeing your comment, I wanted to attach a screenshot of the menu but found an interesting observation in the video attached.

menu-item-change.mov

The Portfolio Dashboard is taking time to load, and as a result, it is clicking Support instead of Settings. I believe this locator strategy should fix the issue.

@hjetpoluru hjetpoluru marked this pull request as draft July 11, 2024 22:54
@metamaskbot
Copy link
Collaborator

Builds ready [ebd025d]
Page Load Metrics (282 ± 290 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint781721162713
domContentLoaded95630147
load482243282604290
domInteractive95630147
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@hjetpoluru hjetpoluru marked this pull request as ready for review July 12, 2024 16:15
Comment on lines 610 to 612
await driver.waitForSelector('[data-testid="global-menu-settings"]');
await driver.clickElement('[data-testid="global-menu-settings"]');
await driver.clickElement({ text: 'Networks', tag: 'div' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just add timeout here since clickElement has findElement inside?

 const element = await this.findClickableElement(rawLocator);
        await element.click();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @DDDDDanica. That's a valid point about adding the timeout. This issue is happening only for the mmi build, and the menu item is changing. So, I have written a conditional wait for the menu in the code below. Let me know your thoughts.

if (process.env.METAMASK_BUILD_TYPE === 'mmi') {
              await driver.wait(async () => {
                const element = await driver.findVisibleElement(
                  '[data-testid="global-menu-mmi-portfolio"]',
                );
                if (!element) {
                  console.log('Element not visible');
                }
              }, 1000);
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DDDDDanica, Thank you for the suggestion.

However, the initial use of waitForSelector but on the Portfolio Dashboard, combined with a conditional check is working effectively

@metamaskbot
Copy link
Collaborator

Builds ready [67a3f7e]
Page Load Metrics (103 ± 32 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint663901357436
domContentLoaded10178493617
load462961036732
domInteractive10178493617
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.96%. Comparing base (24c95db) to head (67a3f7e).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #25786   +/-   ##
========================================
  Coverage    69.96%   69.96%           
========================================
  Files         1390     1390           
  Lines        48919    48919           
  Branches     13460    13460           
========================================
  Hits         34226    34226           
  Misses       14693    14693           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -113,12 +113,27 @@ const selectors = {

async function navigateToAddNetwork(driver) {
await driver.clickElement(selectors.accountOptionsMenuButton);
if (process.env.METAMASK_BUILD_TYPE === 'mmi') {
await checkIfPortfolioDashboardIsVisible(driver);
Copy link
Contributor

Choose a reason for hiding this comment

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

The race-condition identified in this test can also affect other mmi tests: in all tests where we click the Settings icon '[data-testid="account-options-menu-button"]',.

For this reason, we could have a generic function for checking if settings is ready, before proceeding with the next action.

We don't need to do this in this PR, but we could do it in the Page Object implementation, and having this guard for mmi builds can mitigate all flakiness related to the settings re-render case

cc @chloeYue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree with you. We could do it in separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seaona, I have introduced an additional wait for the portfolio dashboard and removed the checkIfPortfolioDashboardIsVisible function.

However, I believe this spec file is critical and contains many test cases that could be implemented using the Page Object Model. Do let me know what you think?

Also, this is completely different discuss and will leave it to @chloeYue

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah agree, POM will definitely help on this !

Copy link
Contributor

@chloeYue chloeYue left a comment

Choose a reason for hiding this comment

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

one small nit, otherwise LGTM !

if (process.env.MMI) {
await driver.waitForSelector('[data-testid="global-menu-mmi-portfolio"]');
}
await driver.waitForSelector(selectors.settingsOption);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is not necessary, because we wait for element to be visible in clickElement function.

@@ -66,7 +66,7 @@ const MOCK_CHAINLIST_RESPONSE = [
const selectors = {
accountOptionsMenuButton: '[data-testid="account-options-menu-button"]',
informationSymbol: '[data-testid="info-tooltip"]',
settingsOption: { text: 'Settings', tag: 'div' },
settingsOption: '[data-testid="global-menu-settings"]',
Copy link
Contributor

@seaona seaona Jul 16, 2024

Choose a reason for hiding this comment

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

I think this change is not strictly needed for fixing the issue, but I guess it's fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this locator strategy was sufficient, and with only this change, the CI has passed. However, I added an additional safety net to check for MMI and wait for the 'Portfolio Dashboard'.

Copy link
Contributor

@chloeYue chloeYue left a comment

Choose a reason for hiding this comment

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

LGTM ! Good job !

Copy link

sonarcloud bot commented Jul 17, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [4386823]
Page Load Metrics (365 ± 312 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint772241213316
domContentLoaded1086352311
load552061365649312
domInteractive1086352311
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@hjetpoluru hjetpoluru merged commit b31c31e into develop Jul 17, 2024
78 of 79 checks passed
@hjetpoluru hjetpoluru deleted the fix-flaky-test-delete-network branch July 17, 2024 13:53
@github-actions github-actions bot locked and limited conversation to collaborators Jul 17, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
flaky tests INVALID-PR-TEMPLATE PR's body doesn't match template release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-extension-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

flaky test: "Custom network Popular Networks List delete the Arbitrum network"
6 participants