test: new switchToWindowWithTitle w/ Extension communication
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
- [x] I've followed MetaMask Contributor Docs and MetaMask Extension Coding Standards.
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using JSDoc format if applicable
- [x] 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.
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 ↗︎
| 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]
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 :warning: |
| app/scripts/offscreen.js | 0.00% | 2 Missing :warning: |
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Builds ready [4fae996]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (201 ± 283 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 69 | 287 | 103 | 46 | 22 |
| domContentLoaded | 9 | 85 | 18 | 17 | 8 | ||
| load | 40 | 2768 | 201 | 590 | 283 | ||
| domInteractive | 9 | 85 | 18 | 17 | 8 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 2.48 KiB (0.07%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [fba217e]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (141 ± 186 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 58 | 115 | 85 | 13 | 6 |
| domContentLoaded | 8 | 14 | 11 | 2 | 1 | ||
| load | 38 | 1827 | 141 | 387 | 186 | ||
| domInteractive | 8 | 14 | 11 | 2 | 1 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 2.48 KiB (0.07%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [a55651a]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (45 ± 2 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 67 | 98 | 76 | 7 | 4 |
| domContentLoaded | 9 | 11 | 10 | 1 | 0 | ||
| load | 40 | 61 | 45 | 5 | 2 | ||
| domInteractive | 9 | 11 | 10 | 1 | 0 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 2.5 KiB (0.07%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
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 :heart_eyes: 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)
Builds ready [11fb79a]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (48 ± 2 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 69 | 89 | 80 | 6 | 3 |
| domContentLoaded | 9 | 16 | 11 | 1 | 1 | ||
| load | 40 | 62 | 48 | 5 | 2 | ||
| domInteractive | 9 | 16 | 11 | 1 | 1 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 2.5 KiB (0.07%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [5ea1bc5]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (63 ± 14 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 62 | 188 | 98 | 42 | 20 |
| domContentLoaded | 9 | 57 | 17 | 13 | 6 | ||
| load | 41 | 136 | 63 | 30 | 14 | ||
| domInteractive | 9 | 57 | 17 | 13 | 6 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 2.5 KiB (0.07%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [299ce1a]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (239 ± 236 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 68 | 302 | 104 | 49 | 23 |
| domContentLoaded | 9 | 62 | 24 | 14 | 7 | ||
| load | 42 | 1803 | 239 | 491 | 236 | ||
| domInteractive | 9 | 62 | 24 | 14 | 7 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 2.48 KiB (0.08%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [09533c6]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (196 ± 221 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 94 | 168 | 130 | 22 | 11 |
| domContentLoaded | 12 | 76 | 34 | 16 | 8 | ||
| load | 62 | 2203 | 196 | 461 | 221 | ||
| domInteractive | 12 | 76 | 34 | 16 | 8 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 3.01 KiB (0.09%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [8b9b1a4]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (171 ± 185 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 67 | 461 | 117 | 81 | 39 |
| domContentLoaded | 9 | 86 | 28 | 20 | 9 | ||
| load | 44 | 1831 | 171 | 384 | 185 | ||
| domInteractive | 9 | 86 | 28 | 20 | 9 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 3.01 KiB (0.09%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Builds ready [bef19fe]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (166 ± 202 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 66 | 287 | 107 | 47 | 22 |
| domContentLoaded | 9 | 79 | 31 | 21 | 10 | ||
| load | 40 | 1996 | 166 | 420 | 202 | ||
| domInteractive | 9 | 79 | 31 | 21 | 10 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 3.01 KiB (0.09%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)