Skip to content

Commit

Permalink
Merge branch 'dev' into ahmed/plugins-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Mar 14, 2023
2 parents f535d06 + fbfd776 commit 98acb5f
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 93 deletions.
89 changes: 46 additions & 43 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,6 @@ const metamask = {
extensionImportTokenUrl,
};
},
// workaround for metamask random blank page on first run
async fixBlankPage() {
await playwright.metamaskWindow().waitForTimeout(1000);
for (let times = 0; times < 5; times++) {
if (
(await playwright
.metamaskWindow()
.locator(onboardingWelcomePageElements.app)
.count()) === 0
) {
await playwright.metamaskWindow().reload();
await playwright.metamaskWindow().waitForTimeout(2000);
} else if (
(await playwright
.metamaskWindow()
.locator(onboardingWelcomePageElements.criticalError)
.count()) > 0
) {
await playwright.metamaskWindow().reload();
await playwright.metamaskWindow().waitForTimeout(2000);
} else {
break;
}
}
},
async closePopupAndTooltips() {
// note: this is required for fast execution of e2e tests to avoid flakiness
// otherwise popup may not be detected properly and not closed
Expand Down Expand Up @@ -202,7 +177,8 @@ const metamask = {
return true;
},
async unlock(password) {
await module.exports.fixBlankPage();
await playwright.fixBlankPage();
await playwright.fixCriticalError();
await playwright.waitAndType(unlockPageElements.passwordInput, password);
await playwright.waitAndClick(
unlockPageElements.unlockButton,
Expand Down Expand Up @@ -608,10 +584,17 @@ const metamask = {
skipSetup,
);
},
async activateEnhancedGasFeeUI(skipSetup) {
async activateEthSignRequests(skipSetup) {
return await activateAdvancedSetting(
experimentalSettingsPageElements.enhancedGasFeeUIToggleOn,
experimentalSettingsPageElements.enhancedGasFeeUIToggleOff,
advancedPageElements.ethSignRequestsToggleOn,
advancedPageElements.ethSignRequestsToggleOff,
skipSetup,
);
},
async activateImprovedTokenAllowance(skipSetup) {
return await activateAdvancedSetting(
experimentalSettingsPageElements.improvedTokenAllowanceToggleOn,
experimentalSettingsPageElements.improvedTokenAllowanceToggleOff,
skipSetup,
true,
);
Expand Down Expand Up @@ -771,15 +754,23 @@ const metamask = {
},
async confirmPermissionToSpend(spendLimit) {
const notificationPage = await playwright.switchToMetamaskNotification();
await playwright.waitAndSetValue(
spendLimit,
notificationPageElements.customSpendingLimitInput,
notificationPage,
);
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
notificationPage,
);
// experimental mode on
if (
await playwright
.metamaskNotificationWindow()
.locator(notificationPageElements.customSpendingLimitInput)
.isVisible()
) {
await playwright.waitAndSetValue(
spendLimit,
notificationPageElements.customSpendingLimitInput,
notificationPage,
);
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
notificationPage,
);
}
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
notificationPage,
Expand Down Expand Up @@ -1149,7 +1140,13 @@ const metamask = {
},
async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, network, password, enableAdvancedSettings },
{
secretWordsOrPrivateKey,
network,
password,
enableAdvancedSettings,
enableExperimentalSettings,
},
) {
const isCustomNetwork =
(process.env.NETWORK_NAME &&
Expand All @@ -1164,7 +1161,8 @@ const metamask = {
await playwright.assignWindows();
await playwright.assignActiveTabName('metamask');
await module.exports.getExtensionDetails();
await module.exports.fixBlankPage();
await playwright.fixBlankPage();
await playwright.fixCriticalError();
if (
await playwright
.metamaskWindow()
Expand All @@ -1180,7 +1178,7 @@ const metamask = {
await module.exports.importAccount(secretWordsOrPrivateKey);
}

await setupSettings(enableAdvancedSettings);
await setupSettings(enableAdvancedSettings, enableExperimentalSettings);

if (isCustomNetwork) {
await module.exports.addNetwork(network);
Expand Down Expand Up @@ -1266,7 +1264,10 @@ async function activateAdvancedSetting(
return true;
}

async function setupSettings(enableAdvancedSettings) {
async function setupSettings(
enableAdvancedSettings,
enableExperimentalSettings,
) {
await switchToMetamaskIfNotActive();
await metamask.goToAdvancedSettings();
await metamask.activateAdvancedGasControl(true);
Expand All @@ -1278,7 +1279,9 @@ async function setupSettings(enableAdvancedSettings) {
await metamask.activateTestnetConversion(true);
}
await metamask.goToExperimentalSettings();
await metamask.activateEnhancedGasFeeUI(true);
if (enableExperimentalSettings) {
await metamask.activateImprovedTokenAllowance(true);
}
await playwright.waitAndClick(
settingsPageElements.closeButton,
await playwright.metamaskWindow(),
Expand Down
34 changes: 34 additions & 0 deletions commands/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const {
notificationPageElements,
} = require('../pages/metamask/notification-page');
const { pageElements } = require('../pages/metamask/page');
const {
onboardingWelcomePageElements,
} = require('../pages/metamask/first-time-flow-page');
// const metamask = require('./metamask');
const sleep = require('util').promisify(setTimeout);

let browser;
Expand Down Expand Up @@ -307,5 +311,35 @@ module.exports = {
);
await module.exports.waitToBeHidden(pageElements.loadingOverlay, page);
}
await module.exports.fixCriticalError();
},
// workaround for metamask random blank page on first run
async fixBlankPage(page = metamaskWindow) {
for (let times = 0; times < 5; times++) {
if (
(await page.locator(onboardingWelcomePageElements.app).count()) === 0
) {
await page.reload();
await module.exports.waitUntilMetamaskWindowIsStable();
} else {
break;
}
}
},
async fixCriticalError(page = metamaskWindow) {
for (let times = 0; times < 5; times++) {
if ((await page.locator(pageElements.criticalError).count()) > 0) {
if (times < 3) {
await page.reload();
} else {
await module.exports.waitAndClick(
pageElements.criticalErrorRestartButton,
);
}
await module.exports.waitUntilMetamaskWindowIsStable();
} else {
break;
}
}
},
};
17 changes: 14 additions & 3 deletions docs/synpress-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,22 @@ activateDismissBackupReminderInMetamask(
): Chainable<Subject>;
```

#### `cy.activateEnhancedGasFeeUIInMetamask()`
#### `cy.activateEthSignRequestsInMetamask()`

Activate enhanced gas fee UI in metamask settings.
Activate eth sign requests in metamask settings.

```ts
activateEnhancedGasFeeUIInMetamask(skipSetup?: boolean): Chainable<Subject>;
activateEthSignRequestsInMetamask(skipSetup?: boolean): Chainable<Subject>;
```

#### `cy.activateImprovedTokenAllowanceInMetamask()`

Activate improved token allowance in metamask settings (experimental).

```ts
activateImprovedTokenAllowanceInMetamask(
skipSetup?: boolean,
): Chainable<Subject>;
```

#### `cy.resetMetamaskAccount()`
Expand Down Expand Up @@ -407,6 +417,7 @@ setupMetamask(
network?: string | object,
password?: string,
enableAdvancedSettings?: boolean,
enableExperimentalSettings?: boolean,
): Chainable<Subject>;
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@synthetixio/synpress",
"version": "3.2.0",
"version": "3.5.0",
"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: 0 additions & 2 deletions pages/metamask/first-time-flow-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ module.exports.metametricsPageElements = {
};

const app = '#app-content .app';
const criticalError = `#app-content .critical-error`;
const onboardingWelcomePage = `${onboardingFlow} [data-testid="onboarding-welcome"]`;
const importWalletButton = `${onboardingWelcomePage} [data-testid="onboarding-import-wallet"]`;
const createWalletButton = `${onboardingWelcomePage} [data-testid="onboarding-create-wallet"]`;
module.exports.onboardingWelcomePageElements = {
app,
criticalError,
onboardingWelcomePage,
importWalletButton,
createWalletButton,
Expand Down
5 changes: 5 additions & 0 deletions pages/metamask/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ const loadingOverlayErrorButtons = '.loading-overlay__error-buttons';
const loadingOverlayErrorButtonsRetryButton =
'.loading-overlay__error-buttons .btn-primary';

const criticalError = '.critical-error';
const criticalErrorRestartButton = '#critical-error-button';

module.exports.pageElements = {
loadingLogo,
loadingSpinner,
loadingOverlay,
loadingOverlaySpinner,
loadingOverlayErrorButtons,
loadingOverlayErrorButtonsRetryButton,
criticalError,
criticalErrorRestartButton,
};
14 changes: 10 additions & 4 deletions pages/metamask/settings-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const dismissBackupReminderOn =
'[data-testid="advanced-setting-dismiss-reminder"] .toggle-button--on';
const dismissBackupReminderOff =
'[data-testid="advanced-setting-dismiss-reminder"] .toggle-button--off';
const ethSignRequestsToggleOn =
'[data-testid="advanced-setting-toggle-ethsign"] .toggle-button--on';
const ethSignRequestsToggleOff =
'[data-testid="advanced-setting-toggle-ethsign"] .toggle-button--off';
module.exports.advancedPageElements = {
resetAccountButton,
advancedGasControlToggleOn,
Expand All @@ -49,15 +53,17 @@ module.exports.advancedPageElements = {
dismissBackupReminderOff,
customNonceToggleOn,
customNonceToggleOff,
ethSignRequestsToggleOn,
ethSignRequestsToggleOff,
};

const enhancedGasFeeUIToggleOn =
const improvedTokenAllowanceToggleOn =
'.settings-page__content-row:nth-child(1) .toggle-button--on';
const enhancedGasFeeUIToggleOff =
const improvedTokenAllowanceToggleOff =
'.settings-page__content-row:nth-child(1) .toggle-button--off';
module.exports.experimentalSettingsPageElements = {
enhancedGasFeeUIToggleOn,
enhancedGasFeeUIToggleOff,
improvedTokenAllowanceToggleOn,
improvedTokenAllowanceToggleOff,
};

const nevermindButton = '.modal-container .btn-secondary';
Expand Down
2 changes: 2 additions & 0 deletions plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ module.exports = (on, config) => {
network,
password,
enableAdvancedSettings,
enableExperimentalSettings,
}) => {
if (process.env.NETWORK_NAME) {
network = process.env.NETWORK_NAME;
Expand All @@ -132,6 +133,7 @@ module.exports = (on, config) => {
network,
password,
enableAdvancedSettings,
enableExperimentalSettings,
});
return true;
},
Expand Down
13 changes: 11 additions & 2 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ Cypress.Commands.add(
);

Cypress.Commands.add(
'activateEnhancedGasFeeUIInMetamask',
'activateEthSignRequestsInMetamask',
(skipSetup = false) => {
return cy.task('activateEnhancedGasFeeUIInMetamask', skipSetup);
return cy.task('activateEthSignRequestsInMetamask', skipSetup);
},
);

Cypress.Commands.add(
'activateImprovedTokenAllowanceInMetamask',
(skipSetup = false) => {
return cy.task('activateImprovedTokenAllowanceInMetamask', skipSetup);
},
);

Expand Down Expand Up @@ -222,12 +229,14 @@ Cypress.Commands.add(
network = 'goerli',
password = 'Tester@1234',
enableAdvancedSettings = false,
enableExperimentalSettings = false,
) => {
return cy.task('setupMetamask', {
secretWordsOrPrivateKey,
network,
password,
enableAdvancedSettings,
enableExperimentalSettings,
});
},
);
Expand Down
15 changes: 12 additions & 3 deletions support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,19 @@ declare namespace Cypress {
skipSetup?: boolean,
): Chainable<Subject>;
/**
* Activate enhanced gas fee UI in metamask settings
* Activate eth sign requests in metamask settings
* @example
* cy.activateEnhancedGasFeeUIInMetamask()
* cy.activateEthSignRequestsInMetamask()
*/
activateEnhancedGasFeeUIInMetamask(skipSetup?: boolean): Chainable<Subject>;
activateEthSignRequestsInMetamask(skipSetup?: boolean): Chainable<Subject>;
/**
* Activate improved token allowance in metamask settings (experimental)
* @example
* cy.activateImprovedTokenAllowanceInMetamask()
*/
activateImprovedTokenAllowanceInMetamask(
skipSetup?: boolean,
): Chainable<Subject>;
/**
* Reset metamask account state in settings
* @example
Expand Down Expand Up @@ -327,6 +335,7 @@ declare namespace Cypress {
network?: string | object,
password?: string,
enableAdvancedSettings?: boolean,
enableExperimentalSettings?: boolean,
): Chainable<Subject>;
/**
* Execute settle on Exchanger contract
Expand Down
Loading

0 comments on commit 98acb5f

Please sign in to comment.