Skip to content

Commit 44515df

Browse files
committed
Fix undefined locator error by adding safety checks for metamaskWindow
1 parent f88edf0 commit 44515df

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

commands/metamask.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,9 +1577,10 @@ const metamask = {
15771577
} else {
15781578
log('[initialSetup] WARNING: metamaskWindow is not available, skipping fixCriticalError');
15791579
}
1580-
if (
1581-
(await playwright
1582-
.metamaskWindow()
1580+
// Check if metamaskWindow is available before calling locator
1581+
const metamaskWindowForOnboarding = await playwright.metamaskWindow();
1582+
if (metamaskWindowForOnboarding &&
1583+
(await metamaskWindowForOnboarding
15831584
.locator(onboardingWelcomePageElements.onboardingWelcomePage)
15841585
.count()) > 0
15851586
) {
@@ -1603,9 +1604,14 @@ const metamask = {
16031604
walletAddress = await module.exports.getWalletAddress();
16041605
await playwright.switchToCypressWindow();
16051606
return true;
1606-
} else if (
1607-
(await playwright
1608-
.metamaskWindow()
1607+
} else {
1608+
log('[initialSetup] WARNING: metamaskWindow is not available, skipping onboarding check');
1609+
}
1610+
1611+
// Check if metamaskWindow is available for unlock check
1612+
const metamaskWindowForUnlock = await playwright.metamaskWindow();
1613+
if (metamaskWindowForUnlock &&
1614+
(await metamaskWindowForUnlock
16091615
.locator(unlockPageElements.passwordInput)
16101616
.count()) > 0
16111617
) {
@@ -1614,9 +1620,10 @@ const metamask = {
16141620
await playwright.switchToCypressWindow();
16151621
return true;
16161622
} else {
1617-
if (
1618-
(await playwright
1619-
.metamaskWindow()
1623+
// Check if metamaskWindow is available for wallet overview check
1624+
const metamaskWindowForOverview = await playwright.metamaskWindow();
1625+
if (metamaskWindowForOverview &&
1626+
(await metamaskWindowForOverview
16201627
.locator(mainPageElements.walletOverview)
16211628
.count()) > 0 &&
16221629
!process.env.RESET_METAMASK
@@ -1718,17 +1725,25 @@ async function activateAdvancedSetting(
17181725
await metamask.goToAdvancedSettings();
17191726
}
17201727
}
1721-
if ((await playwright.metamaskWindow().locator(toggleOn).count()) === 0) {
1728+
// Check if metamaskWindow is available before checking toggle
1729+
const metamaskWindowForToggle = await playwright.metamaskWindow();
1730+
if (metamaskWindowForToggle && (await metamaskWindowForToggle.locator(toggleOn).count()) === 0) {
17221731
await playwright.waitAndClick(toggleOff);
17231732
}
17241733
if (!skipSetup) {
1725-
await playwright.waitAndClick(
1726-
settingsPageElements.closeButton,
1727-
await playwright.metamaskWindow(),
1728-
{
1729-
waitForEvent: 'navi',
1730-
},
1731-
);
1734+
// Check if metamaskWindow is available before clicking close button
1735+
const metamaskWindowForClose = await playwright.metamaskWindow();
1736+
if (metamaskWindowForClose) {
1737+
await playwright.waitAndClick(
1738+
settingsPageElements.closeButton,
1739+
metamaskWindowForClose,
1740+
{
1741+
waitForEvent: 'navi',
1742+
},
1743+
);
1744+
} else {
1745+
log('[setupSettings] WARNING: metamaskWindow is not available, skipping close button click');
1746+
}
17321747
await metamask.closePopupAndTooltips();
17331748
await switchToCypressIfNotActive();
17341749
}

0 commit comments

Comments
 (0)