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(25350): fix flakey token importing e2e test #26351

Merged
merged 2 commits into from
Aug 8, 2024
Merged

Conversation

DDDDDanica
Copy link
Contributor

@DDDDDanica DDDDDanica commented Aug 6, 2024

Description

Captured in https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/95033/workflows/faea9f93-9600-4207-bb3c-2dc17eec663b/jobs/3536505/tests.

This test is flaky from not waiting for token price to be fetched and rendered properly. The simple fix would be

  • wait until token is imported after modal is closed
  • use findVisibleElement and the built in timeout to wait for element to be rendered properly

Attached to this PR is a report here of running it 20 times after the fix and results in no flakiness.

Open in GitHub Codespaces

Related issues

Fixes: #26350

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

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.

@DDDDDanica DDDDDanica self-assigned this Aug 6, 2024
@DDDDDanica DDDDDanica requested a review from a team as a code owner August 6, 2024 16:41
Copy link
Contributor

github-actions bot commented Aug 6, 2024

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.

@@ -42,6 +42,7 @@ describe('Token List', function () {
await driver.clickElement(
'[data-testid="import-tokens-modal-import-button"]',
);
await driver.findElement({ text: 'Token imported', tag: 'h6' });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait until token modal is closed and token is properly imported before asserting

@@ -155,40 +156,30 @@ describe('Token List', function () {
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await importToken(driver);
await driver.delay(500);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed with better await here

await driver.findElement(
`[data-testid="token-increase-decrease-percentage"]`,
)
).getText();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no timeout for this assertion, we need to give the element sometime to render and fetch.

@metamaskbot
Copy link
Collaborator

Builds ready [3bdd4b5]
Page Load Metrics (384 ± 363 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint622971266230
domContentLoaded9185313919
load422537384755363
domInteractive9185313919
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented Aug 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.10%. Comparing base (b109dec) to head (8d5843a).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #26351   +/-   ##
========================================
  Coverage    70.10%   70.10%           
========================================
  Files         1430     1430           
  Lines        50144    50147    +3     
  Branches     13870    13872    +2     
========================================
+ Hits         35149    35152    +3     
  Misses       14995    14995           

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

@DDDDDanica
Copy link
Contributor Author

command_output.txt

desi
desi previously approved these changes Aug 7, 2024
Copy link
Contributor

@desi desi left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -155,40 +156,30 @@ describe('Token List', function () {
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await importToken(driver);
await driver.delay(500);

// Verify native token increase
const testIdNative = `token-increase-decrease-percentage-${zeroAddress()}`;

// Verify native token increase
const testId = `token-increase-decrease-percentage-${tokenAddress}`;

Copy link
Contributor

Choose a reason for hiding this comment

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

We have a recommended pattern for when we need to assert data that might be updated asynchronously. It is best if we have explicit assertions (separate from the findElement call) and it is necessary to also include expected text in the find element call. See the docs for the recommended pattern: https://github.com/MetaMask/contributor-docs/blob/main/docs/e2e/extension-e2e-guidelines.md#guidelines-3

Could you update it to follow that sort of pattern and maintain the use of explicit assert calls?

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 for linking the pattern, it is indeed needed for text assertion, changed here 8d5843a

@DDDDDanica
Copy link
Contributor Author

Updated after 8d5843a
command_output.txt

Copy link

sonarqubecloud bot commented Aug 8, 2024

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [8d5843a]
Page Load Metrics (225 ± 222 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint643261258038
domContentLoaded99026199
load481680225463222
domInteractive99026199
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@benjisclowder benjisclowder left a comment

Choose a reason for hiding this comment

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

LGTM!

@DDDDDanica DDDDDanica merged commit 91dc6ea into develop Aug 8, 2024
78 checks passed
@DDDDDanica DDDDDanica deleted the fix/26350 branch August 8, 2024 20:53
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2024
@metamaskbot metamaskbot added the release-12.4.0 Issue or pull request that will be included in release 12.4.0 label Aug 8, 2024
@gauthierpetetin gauthierpetetin added release-12.3.0 Issue or pull request that will be included in release 12.3.0 and removed release-12.4.0 Issue or pull request that will be included in release 12.4.0 labels Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix "Token List shows percentage increase for an ERC20 to..." flaky tests
6 participants