Skip to content

Commit

Permalink
Promote dev to master (#939)
Browse files Browse the repository at this point in the history
* Remove leftover TODOs

* Remove text based locators

* Add `Known problems with MetaMask` section

* Remove Promise wrap from `cy.setupMetamask()` (#927)

* Fix localized Chrome's extension id (#928)

* Fix localized Chrome's extension id

* Improve id handling

---------

Co-authored-by: Piotr Frankowski <[email protected]>

* Lint

* Feature/revoke permission to all (#932)

* Fix typo in Permission word

* Add permission revoking actions

* Add tests for permission revoking actions

* Regenerate synpress commands file

---------

Co-authored-by: Peter F <[email protected]>
Co-authored-by: Piotr Frankowski <[email protected]>
Co-authored-by: Rafał Majchrzak <[email protected]>
  • Loading branch information
4 people authored Oct 18, 2023
1 parent 81faa92 commit f94c34d
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 115 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ Options:
-h, --help display help for command
```

## 👨‍⚕️ Known problems with MetaMask

If your MetaMask is stuck on the loading screen, check what's happening under the hood in the console. You can find vital information about why it's stuck on this step.

#### ⭐ Sentry.io HTTP error 499 (Request has been forbidden by antivirus)

- Kaspersky antivirus sometimes blocks encrypted requests to Sentry.io. You can disable
this feature in Kaspersky advanced settings by toggling on `"Do not scan encrypted connections"`.

## 📃 Environmental variables

| Variable | Description |
Expand Down
43 changes: 34 additions & 9 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,11 +1221,11 @@ const metamask = {

// 120 seconds
while (retries < retiresLimit) {
const pendingTxs = await playwright // TODO rename
const pendingTxs = await playwright
.metamaskWindow()
.getByText('Pending')
.count();
const queuedTxs = await playwright // TODO rename
const queuedTxs = await playwright
.metamaskWindow()
.getByText('Queued')
.count();
Expand Down Expand Up @@ -1266,13 +1266,19 @@ const metamask = {
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > div`,
)
.filter({ hasNotText: 'History' })
.filter({ hasNotText: 'View more' })
.filter({
has: playwright.metamaskWindow().locator('div.list-item__heading'),
})
.all();

while (txIndex >= visibleTxs.length) {
try {
await playwright.metamaskWindow().getByText('View more').click();
await playwright
.metamaskWindow()
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > button`,
)
.click();
} catch (error) {
log('[openTransactionDetails] Clicking "View more" failed!');
throw new Error(
Expand All @@ -1285,8 +1291,9 @@ const metamask = {
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > div`,
)
.filter({ hasNotText: 'History' })
.filter({ hasNotText: 'View more' })
.filter({
has: playwright.metamaskWindow().locator('div.list-item__heading'),
})
.all();
}

Expand Down Expand Up @@ -1341,7 +1348,7 @@ const metamask = {
);
return true;
},
async confirmPermisionToApproveAll() {
async confirmPermissionToApproveAll() {
const notificationPage = await playwright.switchToMetamaskNotification();
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
Expand All @@ -1354,7 +1361,7 @@ const metamask = {
);
return true;
},
async rejectPermisionToApproveAll() {
async rejectPermissionToApproveAll() {
const notificationPage = await playwright.switchToMetamaskNotification();
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
Expand All @@ -1367,6 +1374,24 @@ const metamask = {
);
return true;
},
async confirmRevokePermissionToAll() {
const notificationPage = await playwright.switchToMetamaskNotification();
await playwright.waitAndClick(
notificationPageElements.allowToSpendButton,
notificationPage,
{ waitForEvent: 'close' },
);
return true;
},
async rejectRevokePermissionToAll() {
const notificationPage = await playwright.switchToMetamaskNotification();
await playwright.waitAndClick(
notificationPageElements.rejectToSpendButton,
notificationPage,
{ waitForEvent: 'close' },
);
return true;
},
async allowToAddNetwork({ waitForEvent } = {}) {
const notificationPage = await playwright.switchToMetamaskNotification();
if (waitForEvent) {
Expand Down
28 changes: 14 additions & 14 deletions commands/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ module.exports = {
activeTabName() {
return activeTabName;
},
async metamaskExtensionId() {
const metamaskExtensionData = (await module.exports.getExtensionsData())
.metamask;
return metamaskExtensionData.id;
},
async setExpectInstance(expect) {
expectInstance = expect;
},
Expand Down Expand Up @@ -87,8 +92,7 @@ module.exports = {
return true;
},
async assignWindows() {
const metamaskExtensionData = (await module.exports.getExtensionsData())
.metamask;
const metamaskExtensionId = await module.exports.metamaskExtensionId();

let pages = await browser.contexts()[0].pages();
for (const page of pages) {
Expand All @@ -97,21 +101,21 @@ module.exports = {
} else if (
page
.url()
.includes(`chrome-extension://${metamaskExtensionData.id}/home.html`)
.includes(`chrome-extension://${metamaskExtensionId}/home.html`)
) {
metamaskWindow = page;
} else if (
page
.url()
.includes(
`chrome-extension://${metamaskExtensionData.id}/notification.html`,
`chrome-extension://${metamaskExtensionId}/notification.html`,
)
) {
metamaskNotificationWindow = page;
} else if (
page
.url()
.includes(`chrome-extension://${metamaskExtensionData.id}/popup.html`)
.includes(`chrome-extension://${metamaskExtensionId}/popup.html`)
) {
metamaskPopupWindow = page;
}
Expand Down Expand Up @@ -161,16 +165,15 @@ module.exports = {
return true;
},
async switchToMetamaskNotification() {
const metamaskExtensionData = (await module.exports.getExtensionsData())
.metamask;
const metamaskExtensionId = await module.exports.metamaskExtensionId();

let pages = await browser.contexts()[0].pages();
for (const page of pages) {
if (
page
.url()
.includes(
`chrome-extension://${metamaskExtensionData.id}/notification.html`,
`chrome-extension://${metamaskExtensionId}/notification.html`,
)
) {
metamaskNotificationWindow = page;
Expand Down Expand Up @@ -337,16 +340,13 @@ module.exports = {
}
},
async waitUntilStable(page) {
const metamaskExtensionData = (await module.exports.getExtensionsData())
.metamask;
const metamaskExtensionId = await module.exports.metamaskExtensionId();

if (
page &&
page
.url()
.includes(
`chrome-extension://${metamaskExtensionData.id}/notification.html`,
)
.includes(`chrome-extension://${metamaskExtensionId}/notification.html`)
) {
await page.waitForLoadState('load');
await page.waitForLoadState('domcontentloaded');
Expand Down Expand Up @@ -477,7 +477,7 @@ module.exports = {

const extensionId = (
await extensionData.locator('#extension-id').textContent()
).replace('ID: ', '');
).split(': ')[1];

extensionsData[extensionName] = {
version: extensionVersion,
Expand Down
Loading

0 comments on commit f94c34d

Please sign in to comment.