1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Interacting with MetaMask Notification window (#12147)

* wait for MetaMask Notification window title to update

* wait for notification to close

* wait for notification to close
This commit is contained in:
PeterYinusa 2021-09-17 20:27:09 +02:00 committed by GitHub
parent 0f86f678f8
commit 49de01c509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 12 deletions

View File

@ -51,9 +51,12 @@ describe('Deploy contract and call contract methods', function () {
await driver.clickElement('#deployButton');
// displays the contract creation data
await driver.switchToWindow(extension);
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.clickElement({ text: 'Contract Deployment', tag: 'h2' });
await driver.waitUntilXWindowHandles(3);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ text: 'Data', tag: 'button' });
await driver.findElement({ text: '127.0.0.1', tag: 'div' });
const confirmDataDiv = await driver.findElement(
@ -68,6 +71,9 @@ describe('Deploy contract and call contract methods', function () {
// confirms a deploy contract transaction
await driver.clickElement({ text: 'Details', tag: 'button' });
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.waitForSelector(
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)',
{ timeout: 10000 },
@ -80,13 +86,13 @@ describe('Deploy contract and call contract methods', function () {
await driver.switchToWindow(dapp);
await driver.clickElement('#depositButton');
await driver.waitUntilXWindowHandles(3);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.waitForSelector(
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(2)',
@ -110,6 +116,7 @@ describe('Deploy contract and call contract methods', function () {
windowHandles,
);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.waitForSelector(
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(3)',

View File

@ -31,7 +31,7 @@ describe('Signature Request', function () {
await driver.clickElement('#signTypedDataV4', 10000);
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
@ -60,6 +60,8 @@ describe('Signature Request', function () {
// Approve signing typed data
await driver.clickElement({ text: 'Sign', tag: 'button' }, 10000);
await driver.waitUntilXWindowHandles(2);
windowHandles = await driver.getAllWindowHandles();
// switch to the Dapp and verify the signed addressed
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);

View File

@ -275,16 +275,25 @@ class Driver {
throw new Error('waitUntilXWindowHandles timed out polling window handles');
}
async switchToWindowWithTitle(title, windowHandles) {
async switchToWindowWithTitle(
title,
windowHandles,
delayStep = 1000,
timeout = 5000,
) {
let timeElapsed = 0;
// eslint-disable-next-line no-param-reassign
windowHandles = windowHandles || (await this.driver.getAllWindowHandles());
for (const handle of windowHandles) {
await this.driver.switchTo().window(handle);
const handleTitle = await this.driver.getTitle();
if (handleTitle === title) {
return handle;
while (timeElapsed <= timeout) {
for (const handle of windowHandles) {
await this.driver.switchTo().window(handle);
const handleTitle = await this.driver.getTitle();
if (handleTitle === title) {
return handle;
}
}
await this.delay(delayStep);
timeElapsed += delayStep;
}
throw new Error(`No window with title: ${title}`);