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

test: new switchToWindowWithTitle w/ Extension communication #25362

Merged
merged 25 commits into from
Jul 23, 2024

Conversation

HowardBraham
Copy link
Contributor

@HowardBraham HowardBraham commented Jun 17, 2024

Description

This creates a Socket between Mocha/Selenium and the Extension background script (service worker in MV3).

I had originally hoped that we could send a message to the Extension, and make the Extension switch windows. But it seems like Selenium's idea of "which tab/window are we looking at" is not the same as which one the browser has active. In fact, the "real user" can change tabs, and Selenium still works on the old tab. So an attempt to change tabs in the browser effectively does nothing.

My second attempt was to send back a list of open tabs and their names. This almost works, except the order of the tab lists is different between the browser list and the Selenium list. So we can't really act on that information to switch to a tab.

So the thing I went for is to ask the Extension to wait until there's a window open with the target title or url, and then inform Mocha/Selenium that it exists and to look for it.

These changes made a small number of tests more flaky, so I made some minor changes to them to work better with the new system.

Open in GitHub Codespaces

Related issues

Manual testing steps

This is a special CircleCI workflow where I run every E2E test 4 times each. Some of these jobs took 40 minutes, with very few failures (and only on existing flaky tests). This PR makes things more stable.
https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/87754/workflows/02b77156-ef91-45d3-9367-e8ebe2ee2f1f

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.

Copy link

socket-security bot commented Jun 17, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/[email protected] None 0 698 kB types
npm/@types/[email protected] None 0 24.9 kB types
npm/@types/[email protected] None 0 8.34 kB types
npm/@types/[email protected] None 0 32.4 kB types
npm/@types/[email protected] None 0 21.2 kB types
npm/[email protected] environment, network 0 141 kB lpinca

🚮 Removed packages: npm/@types/[email protected], npm/[email protected]

View full report↗︎

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 69.67%. Comparing base (a3c4333) to head (bef19fe).
Report is 9 commits behind head on develop.

Files Patch % Lines
app/scripts/background.js 0.00% 2 Missing ⚠️
app/scripts/offscreen.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #25362      +/-   ##
===========================================
- Coverage    69.68%   69.67%   -0.01%     
===========================================
  Files         1405     1405              
  Lines        49701    49705       +4     
  Branches     13738    13740       +2     
===========================================
  Hits         34630    34630              
- Misses       15071    15075       +4     

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

@HowardBraham HowardBraham force-pushed the e2e/switchToWindowWithTitle branch from 2ab973d to 4fae996 Compare June 18, 2024 08:44
@metamaskbot
Copy link
Collaborator

Builds ready [4fae996]
Page Load Metrics (201 ± 283 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint692871034622
domContentLoaded98518178
load402768201590283
domInteractive98518178
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.48 KiB (0.07%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@HowardBraham HowardBraham force-pushed the e2e/switchToWindowWithTitle branch 2 times, most recently from 48dabcd to fba217e Compare June 18, 2024 09:36
@metamaskbot
Copy link
Collaborator

Builds ready [fba217e]
Page Load Metrics (141 ± 186 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint5811585136
domContentLoaded8141121
load381827141387186
domInteractive8141121
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.48 KiB (0.07%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@HowardBraham HowardBraham added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) and removed team-accounts labels Jun 18, 2024
bowensanders
bowensanders previously approved these changes Jun 18, 2024
Copy link
Contributor

@bowensanders bowensanders left a comment

Choose a reason for hiding this comment

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

LGTM

@HowardBraham HowardBraham force-pushed the e2e/switchToWindowWithTitle branch from fba217e to a55651a Compare June 21, 2024 07:01
@metamaskbot
Copy link
Collaborator

Builds ready [a55651a]
Page Load Metrics (45 ± 2 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint67987674
domContentLoaded9111010
load40614552
domInteractive9111010
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.5 KiB (0.07%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@seaona
Copy link
Contributor

seaona commented Jun 21, 2024

But it seems like Selenium's idea of "which tab/window are we looking at" is not the same as which one the browser has active

Really nice catch 😍 this is precisely what happens in the vault decrypt test, where we had 2 windows and webdriver active window didn't match chrome's active window (this)

@HowardBraham HowardBraham force-pushed the e2e/switchToWindowWithTitle branch from ef218a6 to 09533c6 Compare July 22, 2024 23:11
@metamaskbot
Copy link
Collaborator

Builds ready [09533c6]
Page Load Metrics (196 ± 221 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint941681302211
domContentLoaded127634168
load622203196461221
domInteractive127634168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3.01 KiB (0.09%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [8b9b1a4]
Page Load Metrics (171 ± 185 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint674611178139
domContentLoaded98628209
load441831171384185
domInteractive98628209
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3.01 KiB (0.09%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

@HowardBraham HowardBraham removed the DO-NOT-MERGE Pull requests that should not be merged label Jul 23, 2024
@HowardBraham HowardBraham marked this pull request as ready for review July 23, 2024 15:58
@HowardBraham HowardBraham dismissed davidmurdoch’s stale review July 23, 2024 16:01

Fixed everything and he is OOO

@metamaskbot
Copy link
Collaborator

Builds ready [bef19fe]
Page Load Metrics (166 ± 202 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint662871074722
domContentLoaded979312110
load401996166420202
domInteractive979312110
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3.01 KiB (0.09%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Introduced a new socket communication mechanism between Mocha/Selenium and the MetaMask extension's background script to improve E2E test stability.

  • app/scripts/background.js: Added getSocketBackgroundToMocha for socket communication in test environments.
  • app/scripts/offscreen.js: Integrated socket initialization for test environments.
  • test/e2e/background-socket/server-mocha-to-background.ts: New WebSocket server for Mocha/Selenium communication.
  • test/e2e/background-socket/socket-background-to-mocha.ts: New WebSocket client for background script communication.
  • test/e2e/helpers.js: Updated test functions to utilize the new socket communication mechanism.

22 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +27 to +31
if (this.ws) {
console.error(
'ServerMochaToBackground got a second client connection, closing the first one',
);
this.ws.close();
Copy link

Choose a reason for hiding this comment

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

Logic: Potential issue with handling multiple WebSocket connections. Consider adding logic to manage multiple connections more gracefully.

Comment on lines +86 to +88
throw new Error(
`No window found by background script with ${message.property}: ${message.value}`,
);
Copy link

Choose a reason for hiding this comment

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

Logic: Throwing an error here might cause the entire test suite to fail. Consider handling this more gracefully or providing more context.

Copy link
Contributor

@bowensanders bowensanders left a comment

Choose a reason for hiding this comment

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

LGTM✅

@HowardBraham HowardBraham merged commit 291e6b8 into develop Jul 23, 2024
77 of 78 checks passed
@HowardBraham HowardBraham deleted the e2e/switchToWindowWithTitle branch July 23, 2024 22:13
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Jul 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 23, 2024
@HowardBraham HowardBraham added contributor experience An issue that impacts, or planned improvement to, the contributor experience. and removed team-contributor-experience labels Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contributor experience An issue that impacts, or planned improvement to, the contributor experience. release-12.3.0 Issue or pull request that will be included in release 12.3.0
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants