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: flaky anti-pattern getText + assert #28041

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

seaona
Copy link
Contributor

@seaona seaona commented Oct 23, 2024

Description

Continuing the work of removing the e2e anti-pattern of finding the element and then asserting its text.
There are more occurrences, but this work is split in several PRs, for an easy review and a faster ci.
Once all occurrences have been fixed, we'll be able to merge @HowardBraham 's PR for adding a lint rule which prevents introducing it again.

Open in GitHub Codespaces

Related issues

Fixes: (but doesn't yet closes) #19870

Manual testing steps

  1. Check ci

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.

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.

await driver.findElement({
xpath:
"//div[@data-testid='useSafeChainsListValidation']//label[contains(@class, 'toggle-button') and contains(@class, 'toggle-button--on')]",
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to use an xpath here since there's a long list of toggles, without a way of differentiating to which feature belong to

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job!!

@seaona seaona marked this pull request as ready for review October 23, 2024 13:20
@seaona seaona requested a review from a team as a code owner October 23, 2024 13:20
@seaona seaona added flaky tests area-qa Relating to QA work (Quality Assurance) labels Oct 23, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [4cfcca0]
Page Load Metrics (2080 ± 140 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint175528182087284136
domContentLoaded173727882036282135
load174728262080292140
domInteractive17185604522
backgroundConnect10123393316
firstReactRender49139912412
getState56122199
initialActions01000
loadScripts124922131529257124
setupStore1392322311
uiStartup194430452294301145
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@hjetpoluru hjetpoluru left a comment

Choose a reason for hiding this comment

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

I think we could update this one in incremental-security.spec.js.

   const outerSegment = await driver.findElement(
          '.qr-code__address-segments',
        );
        const publicAddress = await outerSegment.getText();

@@ -13,7 +12,7 @@ const FixtureBuilder = require('../../fixture-builder');
describe('Sign in with ethereum', function () {
it('user should be able to confirm sign in with ethereum', async function () {
const expectedSigninMessageTitle =
'This site is requesting to sign in with Account 1';
'This site is requesting to sign in with';
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!!

);
await driver.waitForSelector({
css: '#signTypedDataV4VerifyResult',
text: KNOWN_PUBLIC_KEY_ADDRESSES[0].address.toLocaleLowerCase(),
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: could we have this in variable and then pass the variable. Its ok if you dont make the change too.
let address = KNOWN_PUBLIC_KEY_ADDRESSES[0].address.toLocaleLowerCase()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure I've updated it!

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 this change is needed here, it's clear enough the origin implementation.
But since you already made the change, we can keep it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@chloeYue, yeah you're right. After the change was made, I also feel it's not required. I had noted this point..
My initial thought was to read the value, convert it to lowercase and then pass it.

@seaona, thanks for making the change. Since you've made the adjustment we can skip it for now.

Comment on lines 457 to 460
await driver.waitForSelector({
tag: 'dd',
text: currencySYMBOL,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a more specific data-testid for this element or make be some other approach?
The reason I mention this is - I changed the text for currencySYMBOL from ETH to ET, the test would not fail leading to false negatives.
I also checked for any other unique identifiers but there aren't any so we need to add one in the code.

Copy link
Contributor

@hjetpoluru hjetpoluru Oct 23, 2024

Choose a reason for hiding this comment

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

Update on my previous comment - I think changing the data-testid would work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch! I've added test ids in the app level 🙏

Copy link
Contributor

@hjetpoluru hjetpoluru left a comment

Choose a reason for hiding this comment

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

I think we could update this one in incremental-security.spec.js.

   const outerSegment = await driver.findElement(
          '.qr-code__address-segments',
        );
        const publicAddress = await outerSegment.getText();

@@ -109,12 +109,10 @@ describe('Incremental Security', function () {
await driver.switchToWindow(extension);

// should have the correct amount of eth
let currencyDisplay = await driver.waitForSelector({
await driver.waitForSelector({
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to come up with a different approach because this does not fail if the text is changed for waitForSelector, and it does fail with the previous assertion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @hjetpoluru 👋 I've seen the test fail if the text is changed from 1to another value 🤔 Do you see something different?

fail-selector.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @seaona, thanks for addressing the other issue. I tried changing the value to 0, and it did not fail. I will try again later today but if you can check earlier that would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you @hjetpoluru let me check it and will report back 🙏

Copy link
Contributor

@hjetpoluru hjetpoluru left a comment

Choose a reason for hiding this comment

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

To my surprise this did not fail if the text was changed here

const backupReminder = await driver.findElements({
          xpath:
            "//div[contains(@class, 'home-notification__text') and contains(text(), 'Back up your Secret Recovery Phrase to keep your wallet and funds secure')]",
        });
        assert.equal(backupReminder.length, 1);

@metamaskbot
Copy link
Collaborator

Builds ready [5c99c5c]
Page Load Metrics (1962 ± 108 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint170826421972223107
domContentLoaded169726221928224108
load170626401962225108
domInteractive17109512010
backgroundConnect1089352311
firstReactRender49217924622
getState561272211
initialActions00000
loadScripts12282133143320699
setupStore1176312311
uiStartup194828432191231111
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 51 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-qa Relating to QA work (Quality Assurance) flaky tests team-extension-platform
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

4 participants