-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
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. |
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/@types/[email protected], npm/[email protected] |
Codecov ReportAttention: Patch coverage is
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. |
2ab973d
to
4fae996
Compare
Builds ready [4fae996]
Page Load Metrics (201 ± 283 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
48dabcd
to
fba217e
Compare
Builds ready [fba217e]
Page Load Metrics (141 ± 186 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fba217e
to
a55651a
Compare
Builds ready [a55651a]
Page Load Metrics (45 ± 2 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
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) |
ef218a6
to
09533c6
Compare
Builds ready [09533c6]
Page Load Metrics (196 ± 221 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [8b9b1a4]
Page Load Metrics (171 ± 185 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Quality Gate passedIssues Measures |
Fixed everything and he is OOO
Builds ready [bef19fe]
Page Load Metrics (166 ± 202 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this 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
: AddedgetSocketBackgroundToMocha
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
if (this.ws) { | ||
console.error( | ||
'ServerMochaToBackground got a second client connection, closing the first one', | ||
); | ||
this.ws.close(); |
There was a problem hiding this comment.
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.
throw new Error( | ||
`No window found by background script with ${message.property}: ${message.value}`, | ||
); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM✅
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.
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