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

fix: fixed metamask commands to support v11.15.5 #1132

Merged
merged 11 commits into from
May 28, 2024
140 changes: 83 additions & 57 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,25 +351,36 @@ const metamask = {
},
async importAccount(privateKey) {
await switchToMetamaskIfNotActive();
await module.exports.goToImportAccount();
await module.exports.goToHome();
await module.exports.closePopupAndTooltips();
await playwright.waitAndClick(mainPageElements.accountMenu.button);
await playwright.waitAndClick(
mainPageElements.accountMenu.addAccountButton,
);
await playwright.waitAndClickByText(
mainPageElements.accountMenu.addNewAccountButton,
'Import account',
);
await playwright.waitAndType(
mainPageElements.importAccount.input,
privateKey,
);
await playwright.waitAndClick(
mainPageElements.importAccount.importButton,
await playwright.metamaskWindow(),
{
waitForEvent: 'navi',
},
);
await playwright.waitAndClick(mainPageElements.importAccount.importButton);
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
},
async createAccount(accountName) {
await switchToMetamaskIfNotActive();
await module.exports.goToNewAccount();
await module.exports.goToHome();
await module.exports.closePopupAndTooltips();
await playwright.waitAndClick(mainPageElements.accountMenu.button);
await playwright.waitAndClick(
mainPageElements.accountMenu.addAccountButton,
);
await playwright.waitAndClick(
mainPageElements.accountMenu.addNewAccountButton,
);
if (accountName) {
accountName = accountName.toLowerCase();
await playwright.waitAndType(
Expand Down Expand Up @@ -409,6 +420,7 @@ const metamask = {
);

await playwright.waitAndClick(mainPageElements.renameAccount.invokeInput);

await playwright.waitClearAndType(
newAccountName,
mainPageElements.renameAccount.input,
Expand Down Expand Up @@ -477,11 +489,12 @@ const metamask = {

await switchToMetamaskIfNotActive();
await playwright.waitAndClick(mainPageElements.networkSwitcher.button);

await playwright.waitAndClickByText(
const metamaskPage = await playwright.metamaskWindow();
await playwright.waitFor(
mainPageElements.networkSwitcher.dropdownMenuItem,
network.name,
metamaskPage,
);
await playwright.waitAndClick(`[data-testid*="${network.name}"]`);
await playwright.waitForText(
mainPageElements.networkSwitcher.networkName,
network.name,
Expand Down Expand Up @@ -546,6 +559,7 @@ const metamask = {
addNetworkPageElements.networkNameInput,
network.name,
);

await playwright.waitAndType(
addNetworkPageElements.rpcUrlInput,
network.rpcUrls.default.http[0],
Expand All @@ -571,6 +585,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await playwright.waitAndClick(addNetworkPageElements.switchButton);
await module.exports.closePopupAndTooltips();
await playwright.waitForText(
mainPageElements.networkSwitcher.networkName,
Expand Down Expand Up @@ -642,13 +657,6 @@ const metamask = {
await switchToCypressIfNotActive();
return true;
},
async activateAdvancedGasControl(skipSetup) {
return await activateAdvancedSetting(
advancedPageElements.advancedGasControlToggleOn,
advancedPageElements.advancedGasControlToggleOff,
skipSetup,
);
},
async activateShowHexData(skipSetup) {
return await activateAdvancedSetting(
advancedPageElements.showHexDataToggleOn,
Expand Down Expand Up @@ -776,7 +784,10 @@ const metamask = {
async importToken(tokenConfig) {
let tokenData = {};
await switchToMetamaskIfNotActive();
await module.exports.goToImportToken();
await module.exports.goToHome();
await module.exports.closePopupAndTooltips();
await playwright.waitAndClick(mainPageElements.importToken.tokenTab);
await playwright.waitAndClick(mainPageElements.importToken.button);
if (typeof tokenConfig === 'string') {
await playwright.waitAndType(
mainPageElements.importToken.tokenContractAddressInput,
Expand All @@ -792,13 +803,6 @@ const metamask = {
tokenConfig.address,
);
tokenData.tokenContractAddress = tokenConfig.address;
await playwright.waitAndClick(
mainPageElements.importToken.tokenEditButton,
await playwright.metamaskWindow(),
{
force: true,
},
);
await playwright.waitClearAndType(
tokenConfig.symbol,
mainPageElements.importToken.tokenSymbolInput,
Expand All @@ -811,23 +815,10 @@ const metamask = {
await playwright.waitAndClick(
mainPageElements.importToken.addCustomTokenButton,
await playwright.metamaskWindow(),
{
waitForEvent: 'navi',
},
);
await playwright.waitAndClick(
mainPageElements.importToken.importTokensButton,
await playwright.metamaskWindow(),
{
waitForEvent: 'navi',
},
);
await playwright.waitAndClick(
mainPageElements.asset.backButton,
mainPageElements.importToken.confirmImportTokenContent,
await playwright.metamaskWindow(),
{
waitForEvent: 'navi',
},
);
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
Expand Down Expand Up @@ -864,11 +855,13 @@ const metamask = {
.locator(notificationPageElements.customSpendingLimitInput)
.count()) > 0
) {
await playwright.waitAndSetValue(
spendLimit,
notificationPageElements.customSpendingLimitInput,
notificationPage,
);
if (spendLimit) {
await playwright.waitAndSetValue(
spendLimit,
notificationPageElements.customSpendingLimitInput,
notificationPage,
);
}
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
notificationPage,
Expand All @@ -886,7 +879,6 @@ const metamask = {
await playwright.waitAndClick(
notificationPageElements.rejectToSpendButton,
notificationPage,
{ waitForEvent: 'close' },
);
return true;
},
Expand Down Expand Up @@ -972,6 +964,9 @@ const metamask = {
} = {}) {
let txData = {};
const notificationPage = await playwright.switchToMetamaskNotification();

await proceedAnyway();

if (gasConfig) {
log(
'[confirmTransaction] gasConfig is present, determining transaction type..',
Expand Down Expand Up @@ -1095,7 +1090,7 @@ const metamask = {
);
}
await playwright.waitAndClick(
confirmPageElements.saveCustomGasFeeButton,
confirmPageElements.saveAdvanceCustomGasFeeButton,
notificationPage,
);
}
Expand Down Expand Up @@ -1128,7 +1123,7 @@ const metamask = {
confirmPageElements.recipientButton,
notificationPage,
);
txData.recipientPublicAddress = await playwright.waitAndGetValue(
txData.recipientPublicAddress = await playwright.waitAndGetInputValue(
recipientPopupElements.recipientPublicAddress,
notificationPage,
);
Expand Down Expand Up @@ -1191,6 +1186,9 @@ const metamask = {
// notificationPage,
// );
// }

await proceedAnyway();

log('[confirmTransaction] Confirming transaction..');
await playwright.waitAndClick(
confirmPageElements.confirmButton,
Expand All @@ -1200,6 +1198,31 @@ const metamask = {
txData.confirmed = true;
log('[confirmTransaction] Transaction confirmed!');
return txData;

async function proceedAnyway() {
// click on i want to proceed anyway when transaction gas estimation error is thrown
let proceedAnywayButton1 =
'div.transaction-detail > div > div > div > div > button';
let proceedAnywayButton2 =
'div.transaction-alerts > div.mm-box.mm-banner-base.mm-banner-alert.mm-banner-alert--severity-danger.mm-box--padding-3.mm-box--padding-left-2.mm-box--display-flex.mm-box--gap-2.mm-box--background-color-error-muted.mm-box--rounded-sm > div > button';

if (
(await playwright
.metamaskNotificationWindow()
.locator(proceedAnywayButton1)
.count()) > 0
) {
await playwright.waitAndClick(proceedAnywayButton1, notificationPage);
}
if (
(await playwright
.metamaskNotificationWindow()
.locator(proceedAnywayButton2)
.count()) > 0
) {
await playwright.waitAndClick(proceedAnywayButton2, notificationPage);
}
}
},
async confirmTransactionAndWaitForMining(gasConfig) {
// Before we switch to MetaMask tab we have to make sure the notification window has opened.
Expand Down Expand Up @@ -1283,20 +1306,17 @@ const metamask = {

let visibleTxs = await playwright
.metamaskWindow()
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > div`,
)
.locator(mainPageElements.activityTab.completedTransactionsList)
.filter({
has: playwright.metamaskWindow().locator('div.list-item__heading'),
has: playwright.metamaskWindow().locator('div.transaction-list-item'),
})
.all();

while (txIndex >= visibleTxs.length) {
try {
await playwright
.metamaskWindow()
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > button`,
`${mainPageElements.activityTab.completedTransactionsList} > div`,
)
.click();
} catch (error) {
Expand Down Expand Up @@ -1364,7 +1384,6 @@ const metamask = {
await playwright.waitAndClick(
decryptPageElements.rejectDecryptionRequestButton,
notificationPage,
{ waitForEvent: 'close' },
);
return true;
},
Expand Down Expand Up @@ -1503,6 +1522,10 @@ const metamask = {
.locator(onboardingWelcomePageElements.onboardingWelcomePage)
.count()) > 0
) {
// check terms checkbox
await playwright.waitAndClick(
onboardingWelcomePageElements.onboardingTermsCheckbox,
);
if (secretWordsOrPrivateKey.includes(' ')) {
// secret words
await module.exports.importWallet(secretWordsOrPrivateKey, password);
Expand All @@ -1512,6 +1535,10 @@ const metamask = {
await module.exports.importAccount(secretWordsOrPrivateKey);
}

// Enhanced Transaction Protection
await playwright.waitAndClick(
mainPageElements.accountModal.primaryButton,
);
await setupSettings(enableAdvancedSettings, enableExperimentalSettings);

await module.exports.changeNetwork(network);
Expand Down Expand Up @@ -1601,7 +1628,6 @@ async function setupSettings(
) {
await switchToMetamaskIfNotActive();
await metamask.goToAdvancedSettings();
await metamask.activateAdvancedGasControl(true);
await metamask.activateShowHexData(true);
await metamask.activateShowTestnetNetworks(true);
await metamask.activateCustomNonce(true);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@synthetixio/synpress",
"version": "3.7.2-beta.9",
"packageManager": "pnpm@8.4.0",
"packageManager": "pnpm@9.1.3",
"description": "Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.",
"keywords": [
"Synpress",
Expand Down
2 changes: 2 additions & 0 deletions pages/metamask/first-time-flow-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ module.exports.metametricsPageElements = {
const app = '#app-content .app';
const onboardingWelcomePage = `${onboardingFlow} [data-testid="onboarding-welcome"]`;
const importWalletButton = `${onboardingWelcomePage} [data-testid="onboarding-import-wallet"]`;
const onboardingTermsCheckbox = `${onboardingWelcomePage} [data-testid="onboarding-terms-checkbox"]`;
const createWalletButton = `${onboardingWelcomePage} [data-testid="onboarding-create-wallet"]`;
module.exports.onboardingWelcomePageElements = {
app,
onboardingWelcomePage,
importWalletButton,
createWalletButton,
onboardingTermsCheckbox,
};

const firstTimeFlowImportPage = `${onboardingFlow} [data-testid="import-srp"]`;
Expand Down
Loading
Loading