Repository navigation
test: fix flaky test Test Snap manageState - #47104
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
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. |
✨ Files requiring CODEOWNER review ✨🫰 @MetaMask/core-platform (1 files, +4 -4)
|
Builds ready [c7b22d1] [reused from 7541962]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 2 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [45dc511] [reused from ecf092a]
⚡ Performance Benchmarks (Total: 🟢 5 pass · 🟡 2 warn · 🔴 1 fail)
Bundle Size Diffs
|
Builds ready [79480dc] [reused from 98781cf]
⚡ Performance Benchmarks (Total: 🟢 10 pass · 🟡 1 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [fc9e259] [reused from dcb3981]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 2 warn · 🔴 3 fail)
Bundle Size Diffs
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [e05ce5b] [reused from 295f643]
⚡ Performance Benchmarks (Total: 🟢 11 pass · 🟡 0 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [cc04606] [reused from 3d84399]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 3 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [c98a7cd] [reused from fe6d179]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 4 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [fae36ef]
⚡ Performance Benchmarks (Total: 🟢 6 pass · 🟡 5 warn · 🔴 2 fail)
Bundle Size Diffs
|
|
Builds ready [81c04f7] [reused from 178ee43]
⚡ Performance Benchmarks (Total: 🟢 6 pass · 🟡 5 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [1dda820] [reused from 63d44a1]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 2 warn · 🔴 3 fail)
Bundle Size Diffs
|
|
No release label on PR. Adding release label release-13.57.0 on PR, as PR was added to branch 13.57.0 when release was cut. |



Description
The State Snap test flakes in two places. First, the install confirmation popup is missed while it is still on the loading splash. Later, a second click on Set State or Get State scrolls the page while it clicks, so the click misses the button.
Flake type: Race Conditions on Driver/Helpers Functions / Race Conditions with Windows
Root cause:
screenshot-3.png). The State Snap button still says Connecting (screenshot-2.png).getCurrentWindowPropertiesinwindow-handles.ts) is meant to wait until both the page title and the URL are set.No window with title: MetaMask Dialog. It did not look again.foo: "bar").scrollAndClickButtona second time on those buttons.Solution:
getCurrentWindowProperties, keep waiting while the title is missing or the URL is missing, for up to 2 seconds, checking every 200ms - a popup that already has a URL still waits for its title, and a window that never gets a title does not pause for 5 seconds on every scan.switchToWindowWithProperty, search the open windows again for up to 5 seconds, pausing 250ms between passes, until one matches the title or URL - the install confirmation popup can be found once its title becomes MetaMask Dialog.scrollAndClickButtonon Set State and Get State (encrypted and unencrypted) withclickButton- those buttons are already on screen, so the second click does not start another smooth scroll.Slack: https://consensys.slack.com/archives/CTQAGKY5V/p1792053501583089?thread_ts=1792052619.850169&cid=CTQAGKY5V
Related pull requests:
Test Snap manageState can use the new state API#46836Changelog
CHANGELOG entry: null
Manual testing steps
yarn start:testand leave it running.SELENIUM_BROWSER=chrome yarn test:e2e:single test/e2e/snaps/test-snap-managestate.spec.ts --browser=chrome.Screenshots/Recordings
Before
test-failure-screenshot-1.png: the MetaMask extension home tab on Localhost 8545 showing Account 1 with 25 ETH balance (titleMetaMask, not the dialog window).test-failure-screenshot-2.png(screenshot-2.png): the Test Snaps (http://127.0.0.1:8080) State Snap card (npm:@metamask/manage-state-example-snap), with the connect button disabled and still showingConnectingwith a spinner while the install confirmation popup has not been found.test-failure-screenshot-3.png(screenshot-3.png): the new install confirmation popup (380x600) open on the MetaMask loading splash (fox logo and orange loading spinner), before the page<title>(MetaMask Dialog) andAdd to MetaMaskinstall header have rendered. The window search stops after one 200ms pause (~398ms total) and throwsNo window with title: MetaMask Dialog.foo: "bar"is saved, the#encryptedStateResultbox grows and shifts Set State and Get State down. WithKey(#setStateKey) filled withbazandValue(#dataState) filled with"qux", the secondscrollAndClickButton('sendStateButton')scrolls smoothly and clicks during that scroll, so the next entry (baz: "qux") is never submitted.After
No product UI change. The window helper waits for the popup title and searches again for up to 5 seconds, so the install confirmation dialog is found after the splash screen. The second click on each State Snap button clicks in place and does not scroll the page again.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Changes are limited to e2e helpers and one snap spec; no production extension or wallet logic is modified.
Overview
Fixes flaky Test Snap manageState e2e by tightening Selenium window discovery and avoiding redundant smooth-scroll clicks.
In
window-handles.ts,getCurrentWindowPropertiesnow keeps polling until both title and URL are present (not only when both are missing), for up to 2s every 200ms, so install popups on the loading splash are not misclassified beforeMetaMask Dialogappears.switchToWindowWithPropertyretries finding a matching tab for up to 5s (250ms between passes) via a new#findHandleWithPropertyhelper instead of scanning once and failing immediately.In
test-snap-managestate.spec.ts, follow-up clicks on Set/Get State (encrypted and unencrypted) useclickButtoninstead ofscrollAndClickButtonso the second interaction does not scroll while clicking after the result panel grows.Reviewed by Cursor Bugbot for commit 1dda820. Bugbot is set up for automated code reviews on this repo. Configure here.