Skip to content

fix: Update and fix e2e tests to handle the presence of the offscreen document under MV3#24675

Merged
danjm merged 4 commits intodevelopfrom
handle-offscreen-document-e2e
May 23, 2024
Merged

fix: Update and fix e2e tests to handle the presence of the offscreen document under MV3#24675
danjm merged 4 commits intodevelopfrom
handle-offscreen-document-e2e

Conversation

@danjm
Copy link
Copy Markdown
Contributor

@danjm danjm commented May 21, 2024

Description

Our MV3 builds add a "Offscreen Document" to our extension. This means that when our e2e tests call driver.getAllWindowHandles(), a new window is included in the list (the window for the offscreen document). This PR updates the e2e tests to handle this change. Comments are left on each file to explain why the change was needed.

Open in GitHub Codespaces

Related issues

Fixes: #21496

Manual testing steps

Any of the test files modified in this PR should pass when run locally with MV3 builds

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). 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.

@danjm danjm requested a review from a team as a code owner May 21, 2024 09:46
@github-actions
Copy link
Copy Markdown
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 May 21, 2024
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

switchToOrOpenDapp attempts "an unusually fast switchToWindowWithTitle, just 1 second" and if that fails, then calls openDapp. The problem the switchToWindowWithTitle assumes that there will be a window other than the offscreen document present. It seems that openDapp fails if the drivers current window is the offscreen document. The change in this file ensures that, for this e2e test, the extension window is selected first and then the dapp can be opened from there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is needed for the update to test/e2e/json-rpc/switchEthereumChain.spec.js, which can be seen below

@danjm danjm force-pushed the handle-offscreen-document-e2e branch from 1021d45 to 584a572 Compare May 21, 2024 09:51
@@ -53,13 +53,8 @@ describe('Switch Ethereum Chain for two dapps', function () {
await driver.clickElement('.request-queue-toggle');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file assumed that window handles at certain indices would always map to the dapps that are opened. The problem is that the offscreen document can actually be one of the window handles at those indices, The solution is to return the new handle with the openDapp call, and then use that handle to select the right windows for the opened dapps

@@ -33,28 +33,25 @@ describe('Full-size View Setting @no-mmi', function () {
await unlockWallet(driver);
await toggleFullSizeViewSetting(driver);
await openDapp(driver);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file assumed that window handles at certain indices would always map to the dapp and popup window, but again the offscreen document can be at one of these indices.

The solution, which maintains what this test was actually testing, is to update it to compare window handles before and after the user action being tested, and to make an assertion against the new window handle

@@ -176,8 +176,7 @@ describe('Editing Confirm Transaction', function () {
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Instead of selecting window handles by assumed indices, which could end up switching to the offscreen window, this file switches to windows based on title

WINDOW_TITLES,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Instead of selecting window handles by assumed indices, which could end up switching to the offscreen window, this file switches to windows based on title

@@ -509,8 +509,9 @@ class Driver {
}

async openNewPage(url) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is needed to support the changes in switchEthereumChain.spec.js (which can be seen above)

return await this.driver.getAllWindowHandles();
}

async waitUntilXWindowHandles(x, delayStep = 1000, timeout = this.timeout) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Under MV3, there will always be 1 more window handle than previously assumed, so this is a global fix for waitUntilXWindowHandles, to accomodate the MV3 offscreen document

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [584a572]
Page Load Metrics (1365 ± 698 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint681911144019
domContentLoaded1087252210
load54379613651453698
domInteractive1087252210
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@danjm danjm changed the title Update and fix e2e tests to handle the presence of the offscreen document under MV3 fix: Update and fix e2e tests to handle the presence of the offscreen document under MV3 May 21, 2024
@danjm danjm added the team-extension-platform Extension Platform team label May 21, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [f896bed]
Page Load Metrics (1357 ± 679 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint732061283919
domContentLoaded117324168
load61361813571415679
domInteractive117324168
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@danjm
Copy link
Copy Markdown
Contributor Author

danjm commented May 22, 2024

The test-e2e-chrome failure here is related to changes in this PR in the request-queue test. I thought that change would be safe for mv2... I will investigate

@codecov
Copy link
Copy Markdown

codecov bot commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.42%. Comparing base (0ef3c22) to head (4e31e06).
Report is 23 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #24675   +/-   ##
========================================
  Coverage    67.42%   67.42%           
========================================
  Files         1289     1289           
  Lines        50241    50241           
  Branches     13014    13014           
========================================
  Hits         33871    33871           
  Misses       16370    16370           

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

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [4e31e06]
Page Load Metrics (650 ± 481 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint65151942311
domContentLoaded94915105
load5424436501001481
domInteractive94915105
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@danjm
Copy link
Copy Markdown
Contributor Author

danjm commented May 23, 2024

The test-e2e-chrome failure here is related to changes in this PR in the request-queue test. I thought that change would be safe for mv2... I will investigate

I was unable to repro this locally, and it didn't occur again after multiple re-runs on CI (two on this branch and two on another branch I pushed up).

There probably is some flakiness here, but it is hard to recreate, even on CI. I am going to merge and then we can observe if this flake happens again, as we will have this test running more frequently once merge.

@danjm danjm merged commit 9db82cf into develop May 23, 2024
@danjm danjm deleted the handle-offscreen-document-e2e branch May 23, 2024 10:35
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2024
@metamaskbot metamaskbot added release-11.16.6 Issue or pull request that will be included in release 11.16.6 and removed release-11.18.0 labels Jun 4, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Missing release label release-11.16.6 on PR. Adding release label release-11.16.6 on PR and removing other release labels(release-11.18.0), as PR was cherry-picked in branch 11.16.6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-11.16.6 Issue or pull request that will be included in release 11.16.6 team-extension-platform Extension Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Fix and create a success e2e tests pipeline against mv3 build

4 participants