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 related to change language spec #27590

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

hjetpoluru
Copy link
Contributor

@hjetpoluru hjetpoluru commented Oct 3, 2024

Description

The test was initially written to change the language in the settings. Due to the dropdown not closing properly, the line await driver.navigate() was used to refresh the page. However, with recent changes in navigation, this step now appears to cause a driver/browser error.

To resolve this issue, instead of refreshing the page it is more logical to close the settings page by clicking the close button after changing the language. Upon @chloeYue suggestion by replacing the line await driver.navigate() with await driver.clickElementAndWaitToDisappear('.settings-page__header__title-container__close-button') solves the flaky test.

Open in GitHub Codespaces

Related issues

Fixes:
#27390

Manual testing steps

Run the change language spec locally or in codespace using below commands against chrome browser:
yarn
yarn build:test:webpack
ENABLE_MV3=false yarn test:e2e:single test/e2e/tests/settings/change-language.spec.ts --browser=chrome

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.

@hjetpoluru hjetpoluru added team-extension-platform area-qa Relating to QA work (Quality Assurance) labels Oct 3, 2024
@hjetpoluru hjetpoluru self-assigned this Oct 3, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 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.

@hjetpoluru hjetpoluru marked this pull request as ready for review October 4, 2024 12:34
@hjetpoluru hjetpoluru requested a review from a team as a code owner October 4, 2024 12:34
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 4, 2024
Copy link
Contributor

@seaona seaona left a comment

Choose a reason for hiding this comment

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

we should also get rid of the driver.refresh() from here

@hjetpoluru
Copy link
Contributor Author

hjetpoluru commented Oct 4, 2024

Thanks @seaona for the feedback. The test scenario involves refreshing the page to ensure that the language change is retained. Hence the refresh is required. However the current title of the test scenario is misleading and does not clearly represent this purpose. I can update the title to better reflect the scenario or do you want me to remove the scenario.

Also I see in the CI its failing due to the reason about the Error: failed to fetch es locale because of TypeError: Failed to fetch. I think we should fix this issue too.

@seaona
Copy link
Contributor

seaona commented Oct 4, 2024

Thanks @seaona for the feedback. The test scenario involves refreshing the page to ensure that the language change is retained. Hence the refresh is required. However the current title of the test scenario is misleading and does not clearly represent this purpose. I can update the title to better reflect the scenario or do you want me to remove the scenario.

oh I see. So the test is currently failing on ci at the refresh point, for the same reason that it was failing on navigate. If this refresh is part of the test, I think we'll need to await until at least one word has changed to the new language, before refreshing. This can mitigate the race condition below

Screenshot from 2024-10-04 15-01-41

Let me know if this makes sense!

@hjetpoluru
Copy link
Contributor Author

Thanks @seaona for the feedback. The test scenario involves refreshing the page to ensure that the language change is retained. Hence the refresh is required. However the current title of the test scenario is misleading and does not clearly represent this purpose. I can update the title to better reflect the scenario or do you want me to remove the scenario.

oh I see. So the test is currently failing on ci at the refresh point, for the same reason that it was failing on navigate. If this refresh is part of the test, I think we'll need to await until at least one word has changed to the new language, before refreshing. This can mitigate the race condition below

Screenshot from 2024-10-04 15-01-41

Let me know if this makes sense!

I think we both agree on the CI failures, but we are considering different approaches to fix them.

  • My approach was to address the type error itself.
  • I did not fully understand the statement, "we'll need to await until at least one word has changed to the new language." Could you please clarify this? Currently, the test checks the language and then performs a page refresh.

@seaona
Copy link
Contributor

seaona commented Oct 4, 2024

Despite changing the language and checking Idioma actual is there, the language hasn't fully changed until the loading disappears, ie when the language is set to Español. If you do a refresh without waiting for the full language to be changed and loaded into the wallet, we run into the error above.

You can observe this in the video -- Idioma actual is present, but we are still at English language and a loading spinner happens:

language-loading.mp4

@hjetpoluru
Copy link
Contributor Author

@seaona, Thank you. I see it clearly now with the video you have posted. I appreciate your patience in explaining this to me. I will add a wait for the text to be fully loaded before performing the refresh.

@hjetpoluru hjetpoluru requested a review from seaona October 4, 2024 13:37
@hjetpoluru
Copy link
Contributor Author

@seaona, I have pushed the changes you suggested. Please take a look at your convenience. Locally, everything has been working fine, and I will rerun the tests again the CI to verify.

HowardBraham
HowardBraham previously approved these changes Oct 4, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [df9b75e]
Page Load Metrics (1678 ± 54 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31420371607321154
domContentLoaded14511892164010450
load14591976167811354
domInteractive15162463818
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Comment on lines 66 to 69
await driver.assertElementNotPresent('.loading-overlay__spinner');

await driver.findVisibleElement(selectors.labelSpanish);

Copy link
Contributor

Choose a reason for hiding this comment

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

hi @hjetpoluru my suggestion is to add this conditions before doing the refresh. Otherwise we'd still can run into the race condition when refreshing. Let me know if this makes sense 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops! I thought it was needed after the refresh and before clicking on the dropdown again, cause the overlay appears.

@seaona reading this comment, I feel it would be better to include it both before(just wait for overlay) and after(overlay is gone and the label is visible). Please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

   await changeLanguage(driver, languageIndex);
   await driver.assertElementNotPresent('.loading-overlay__spinner');

    // Validate the label changes to Spanish
    const isLanguageLabelChanged = await driver.isElementPresent(
      selectors.labelSpanish,
    );
    assert.equal(isLanguageLabelChanged, true, 'Language did not change');

    await driver.refresh();

    await driver.assertElementNotPresent('.loading-overlay__spinner');
    await driver.findVisibleElement(selectors.labelSpanish);

Copy link
Contributor

@seaona seaona Oct 9, 2024

Choose a reason for hiding this comment

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

yeah I think it's okay. I would keep the labelSpanish before the refresh too, since this needs to happen, to ensure we don't refresh before fetching the language change.

We do have a validation that the language changed below, so I think we can remove the labelSpanish after the refresh (mainly doing the same thing)


   await changeLanguage(driver, languageIndex);
   await driver.assertElementNotPresent('.loading-overlay__spinner');
   await driver.waitForSelector(selectors.labelSpanish);

    // Validate the label changes to Spanish
    const isLanguageLabelChanged = await driver.isElementPresent(
      selectors.labelSpanish,
    );
    assert.equal(isLanguageLabelChanged, true, 'Language did not change');

    await driver.refresh();

    await driver.assertElementNotPresent('.loading-overlay__spinner');

let me know if this makes sense!

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 @seaona for guiding me through this change. That makes sense and I will make the change and push up.

Copy link

sonarcloud bot commented Oct 9, 2024

@hjetpoluru
Copy link
Contributor Author

After getting the latest develop updates, the test failed on this scenario, which is the intended change. Hence, I am converting this PR as draft for further investigation.

Thanks @seaona and @HowardBraham for reviewing this PR and if there is any suggestion please do let me know.

@hjetpoluru hjetpoluru marked this pull request as draft October 9, 2024 17:19
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) INVALID-PR-TEMPLATE PR's body doesn't match template team-extension-platform
Projects
Status: Needs more work from the author
Development

Successfully merging this pull request may close these issues.

4 participants