From 5227d6f3f7a75570384ce4a0b169f491ef412eb2 Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:52:00 +0100 Subject: [PATCH] fix: flaky test `BTC Account - Overview has balance` (#28181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Anti-pattern where we assert the balance BTC balance is 1BTC using getText. We should rather find the element by the expected balance to avoid race conditions [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28181?quickstart=1) ## **Related issues** Fixes: https://github.com/MetaMask/metamask-extension/issues/28182 ## **Manual testing steps** 1. Check ci ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. --- .../flask/btc/btc-account-overview.spec.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/e2e/flask/btc/btc-account-overview.spec.ts b/test/e2e/flask/btc/btc-account-overview.spec.ts index f32a48d9c4a8..418c9d736078 100644 --- a/test/e2e/flask/btc/btc-account-overview.spec.ts +++ b/test/e2e/flask/btc/btc-account-overview.spec.ts @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import { Suite } from 'mocha'; import { DEFAULT_BTC_BALANCE } from '../../constants'; import { withBtcAccountSnap } from './common-btc'; @@ -46,17 +45,19 @@ describe('BTC Account - Overview', function (this: Suite) { await withBtcAccountSnap( { title: this.test?.fullTitle() }, async (driver) => { - // Wait for the balance to load up - await driver.delay(2000); - - const balanceElement = await driver.findElement( - '.coin-overview__balance', - ); - const balanceText = await balanceElement.getText(); + await driver.waitForSelector({ + testId: 'account-value-and-suffix', + text: `${DEFAULT_BTC_BALANCE}`, + }); + await driver.waitForSelector({ + css: '.currency-display-component__suffix', + text: 'BTC', + }); - const [balance, unit] = balanceText.split('\n'); - assert(Number(balance) === DEFAULT_BTC_BALANCE); - assert(unit === 'BTC'); + await driver.waitForSelector({ + tag: 'p', + text: `${DEFAULT_BTC_BALANCE} BTC`, + }); }, ); });