1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

[FLASK] Update e2e tests for new react test-snaps page (#16324)

* Creates updated e2e tests compatible with the new react based test-snaps page.
This commit is contained in:
Bowen Sanders 2022-11-16 13:47:51 -08:00 committed by GitHub
parent 7caeee9ea3
commit 327272f71e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 350 additions and 186 deletions

View File

@ -1,3 +1,3 @@
module.exports = { module.exports = {
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/test-snaps/3.2.0', TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/test-snaps/4.0.2/',
}; };

View File

@ -15,10 +15,9 @@ describe('Test Snap bip-32', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -32,20 +31,38 @@ describe('Test Snap bip-32', function () {
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.driver.get(TEST_SNAPS_WEBSITE_URL);
await driver.delay(1000); await driver.delay(1000);
// find and scroll to the correct card and click first // find and scroll to the bip32 test and connect
const snapButton = await driver.findElement('#sendUpdateHello'); const snapButton1 = await driver.findElement('#connectBip32');
await driver.scrollToElement(snapButton); await driver.scrollToElement(snapButton1);
await driver.delay(500); await driver.delay(1000);
await driver.fill('#snapId6', 'npm:@metamask/test-snap-bip32');
await driver.clickElement('#connectBip32'); await driver.clickElement('#connectBip32');
// approve install of snap // switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles(); let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
); );
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// switch to metamask extension
await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
// approve install of snap
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ await driver.clickElement({
text: 'Approve & install', text: 'Approve & install',
tag: 'button', tag: 'button',
@ -65,10 +82,46 @@ describe('Test Snap bip-32', function () {
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
// scroll to and click get public key
await driver.delay(1000);
const snapButton2 = await driver.findElement('#bip32GetPublic');
await driver.scrollToElement(snapButton2);
await driver.delay(1000);
await driver.clickElement('#bip32GetPublic');
// check for proper public key response
await driver.delay(1000);
const retrievePublicKeyResult1 = await driver.findElement(
'#bip32PublicKeyResult',
);
assert.equal(
await retrievePublicKeyResult1.getText(),
'"0x043e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366606ece56791c361a2320e7fad8bcbb130f66d51c591fc39767ab2856e93f8dfb"',
);
// scroll to and click get compressed public key
await driver.delay(1000);
const snapButton3 = await driver.findElement(
'#bip32GetCompressedPublic',
);
await driver.scrollToElement(snapButton3);
await driver.delay(1000);
await driver.clickElement('#bip32GetCompressedPublic');
// check for proper public key response
await driver.delay(1000);
const retrievePublicKeyResult2 = await driver.findElement(
'#bip32PublicKeyResult',
);
assert.equal(
await retrievePublicKeyResult2.getText(),
'"0x033e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366"',
);
// wait then run SECP256K1 test // wait then run SECP256K1 test
await driver.delay(1000); await driver.delay(1000);
await driver.fill('#bip32SignMessage', 'foo bar'); await driver.fill('#bip32Message-secp256k1', 'foo bar');
await driver.clickElement('#sendBip32Secp256k1'); await driver.clickElement('#sendBip32-secp256k1');
// hit 'approve' on the custom confirm // hit 'approve' on the custom confirm
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
@ -89,16 +142,23 @@ describe('Test Snap bip-32', function () {
// check result // check result
await driver.delay(1000); await driver.delay(1000);
const secp256k1Result = await driver.findElement( const secp256k1Result = await driver.findElement(
'#bip32Secp256k1Result', '#bip32MessageResult-secp256k1',
); );
assert.equal( assert.equal(
await secp256k1Result.getText(), await secp256k1Result.getText(),
'Signature: "0xd30561eb9e3195e47d49198fb0bc66eda867a7dff4c5e8b60c2ec13851aa7d8cc3d485da177de63dad331f315d440cbb693a629efe228389c4693ea90465b101"', '"0x3045022100b3ade2992ea3e5eb58c7550e9bddad356e9554233c8b099ebc3cb418e9301ae2022064746e15ae024808f0ba5d860e44dc4c97e65c8cba6f5ef9ea2e8c819930d2dc"',
); );
// scroll further into messages section
await driver.delay(1000);
const snapButton4 = await driver.findElement('#bip32Message-ed25519');
await driver.scrollToElement(snapButton4);
await driver.delay(1000);
// wait then run ed25519 test // wait then run ed25519 test
await driver.delay(1000); await driver.delay(1000);
await driver.clickElement('#sendBip32Ed25519'); await driver.fill('#bip32Message-ed25519', 'foo bar');
await driver.clickElement('#sendBip32-ed25519');
// hit 'approve' on the custom confirm // hit 'approve' on the custom confirm
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
@ -118,38 +178,12 @@ describe('Test Snap bip-32', function () {
// check result // check result
await driver.delay(1000); await driver.delay(1000);
const ed25519Result = await driver.findElement('#bip32Ed25519Result'); const ed25519Result = await driver.findElement(
'#bip32MessageResult-ed25519',
);
assert.equal( assert.equal(
await ed25519Result.getText(), await ed25519Result.getText(),
'Signature: "0xf3215b4d6c59aac7e01b4ceef530d1e2abf4857926b85a81aaae3894505699243768a887b7da4a8c2e0f25196196ba290b6531050db8dc15c252bdd508532a0a"', '"0xf3215b4d6c59aac7e01b4ceef530d1e2abf4857926b85a81aaae3894505699243768a887b7da4a8c2e0f25196196ba290b6531050db8dc15c252bdd508532a0a"',
);
const publicKeyButton = await driver.findElement('#sendBip32PublicKey');
await driver.scrollToElement(publicKeyButton);
// wait then run public key test
await driver.delay(1000);
await driver.clickElement('#sendBip32PublicKey');
// check result
await driver.delay(1000);
const publicKeyResult = await driver.findElement(
'#bip32PublicKeyResult',
);
assert.equal(
await publicKeyResult.getText(),
'Public key: "0x043e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366606ece56791c361a2320e7fad8bcbb130f66d51c591fc39767ab2856e93f8dfb"',
);
// wait then run compressed public key test
await driver.delay(1000);
await driver.clickElement('#sendBip32CompressedPublicKey');
// check result
await driver.delay(1000);
const compressedPublicKeyResult = await driver.findElement(
'#bip32CompressedPublicKeyResult',
);
assert.equal(
await compressedPublicKeyResult.getText(),
'Public key: "0x033e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366"',
); );
}, },
); );

View File

@ -16,10 +16,9 @@ describe('Test Snap bip-44', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -31,23 +30,37 @@ describe('Test Snap bip-44', function () {
// navigate to test snaps page and connect // navigate to test snaps page and connect
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.driver.get(TEST_SNAPS_WEBSITE_URL);
const snapButton1 = await driver.findElement('#connectBip44Snap');
await driver.scrollToElement(snapButton1);
await driver.delay(1000); await driver.delay(1000);
await driver.fill('#snapId3', 'npm:@metamask/test-snap-bip44'); await driver.clickElement('#connectBip44Snap');
const snapButton = await driver.findElement('#snapId3'); // switch to metamask extension and click connect
await driver.scrollToElement(snapButton);
await driver.delay(500);
// connect the snap
await driver.clickElement('#connectBip44');
// approve install of snap
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles(); let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
); );
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// switch to metamask extension
await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
// approve install of snap
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ await driver.clickElement({
text: 'Approve & install', text: 'Approve & install',
tag: 'button', tag: 'button',
@ -66,14 +79,47 @@ describe('Test Snap bip-44', function () {
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000); await driver.delay(1000);
await driver.clickElement('#sendBip44'); await driver.clickElement('#sendBip44Test');
// check the results of the public key test // check the results of the public key test
await driver.delay(2000); await driver.delay(1000);
const bip44Result = await driver.findElement('#bip44Result'); const bip44Result = await driver.findElement('#bip44Result');
assert.equal( assert.equal(
await bip44Result.getText(), await bip44Result.getText(),
'Public key: "0x86debb44fb3a984d93f326131d4c1db0bc39644f1a67b673b3ab45941a1cea6a385981755185ac4594b6521e4d1e08d1"', '"0x86debb44fb3a984d93f326131d4c1db0bc39644f1a67b673b3ab45941a1cea6a385981755185ac4594b6521e4d1e08d1"',
);
// enter a message to sign
await driver.fill('#bip44Message', '1234');
await driver.delay(1000);
const snapButton3 = await driver.findElement('#signBip44Message');
await driver.scrollToElement(snapButton3);
await driver.delay(1000);
await driver.clickElement('#signBip44Message');
// Switch to approve signature message window and approve
await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({
text: 'Approve',
tag: 'button',
});
// switch back to test-snaps page
await driver.waitUntilXWindowHandles(1, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000);
// check the results of the message signature
const bip44SignResult = await driver.findElement('#bip44SignResult');
assert.equal(
await bip44SignResult.getText(),
'"0xa41ab87ca50606eefd47525ad90294bbe44c883f6bc53655f1b8a55aa8e1e35df216f31be62e52c7a1faa519420e20810162e07dedb0fde2a4d997ff7180a78232ecd8ce2d6f4ba42ccacad33c5e9e54a8c4d41506bdffb2bb4c368581d8b086"',
); );
}, },
); );

View File

@ -16,10 +16,9 @@ describe('Test Snap Confirm', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -31,12 +30,31 @@ describe('Test Snap Confirm', function () {
// navigate to test snaps page and connect // navigate to test snaps page and connect
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.driver.get(TEST_SNAPS_WEBSITE_URL);
await driver.fill('#snapId1', 'npm:@metamask/test-snap-confirm'); const snapButton1 = await driver.findElement('#connectConfirmSnap');
await driver.clickElement('#connectHello'); await driver.scrollToElement(snapButton1);
await driver.delay(1000);
await driver.clickElement('#connectConfirmSnap');
// switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(2, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap // approve install of snap
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
@ -46,14 +64,14 @@ describe('Test Snap Confirm', function () {
tag: 'button', tag: 'button',
}); });
// click send inputs on test snap page // switch back to test snaps page
await driver.waitUntilXWindowHandles(1, 5000, 10000); await driver.waitUntilXWindowHandles(1, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
const snapButton = await driver.findElement('#sendConfirmButton'); // click send inputs on test snap page
await driver.scrollToElement(snapButton); const snapButton2 = await driver.findElement('#sendConfirmButton');
await driver.scrollToElement(snapButton2);
await driver.delay(1000); await driver.delay(1000);
await driver.clickElement('#sendConfirmButton'); await driver.clickElement('#sendConfirmButton');

View File

@ -1,6 +1,5 @@
const { strict: assert } = require('assert'); const { strict: assert } = require('assert');
const { withFixtures } = require('../helpers'); const { withFixtures } = require('../helpers');
const { PAGES } = require('../webdriver/driver');
const FixtureBuilder = require('../fixture-builder'); const FixtureBuilder = require('../fixture-builder');
const { TEST_SNAPS_WEBSITE_URL } = require('./enums'); const { TEST_SNAPS_WEBSITE_URL } = require('./enums');
@ -17,10 +16,9 @@ describe('Test Snap Error', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -31,17 +29,31 @@ describe('Test Snap Error', function () {
await driver.press('#password', driver.Key.ENTER); await driver.press('#password', driver.Key.ENTER);
// navigate to test snaps page and connect // navigate to test snaps page and connect
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
await driver.fill('#snapId2', 'npm:@metamask/test-snap-error'); const snapButton = await driver.findElement('#connectErrorSnap');
const snapButton = await driver.findElement('#connectError');
await driver.scrollToElement(snapButton); await driver.scrollToElement(snapButton);
await driver.delay(500); await driver.delay(1000);
await driver.clickElement('#connectErrorSnap');
await driver.clickElement('#connectError'); // switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(3, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles();
const extensionPage = windowHandles[0];
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap // approve install of snap
let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
@ -52,14 +64,19 @@ describe('Test Snap Error', function () {
}); });
// click send inputs on test snap page // click send inputs on test snap page
await driver.waitUntilXWindowHandles(1, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000); await driver.delay(1000);
// find and click on send error
await driver.clickElement('#sendError'); await driver.clickElement('#sendError');
await driver.navigate(PAGES.HOME); // switch back to the extension page
await driver.switchToWindow(extensionPage);
await driver.delay(1000);
// look for the actual error and check if it is correct
const error = await driver.findElement( const error = await driver.findElement(
'.home-notification__content-container', '.home-notification__content-container',
); );
@ -70,6 +87,12 @@ describe('Test Snap Error', function () {
), ),
true, true,
); );
// try to click on the dismiss button and pass test if it works
await driver.clickElement({
text: 'Dismiss',
tag: 'button',
});
}, },
); );
}); });

View File

@ -3,8 +3,8 @@ const { withFixtures } = require('../helpers');
const FixtureBuilder = require('../fixture-builder'); const FixtureBuilder = require('../fixture-builder');
const { TEST_SNAPS_WEBSITE_URL } = require('./enums'); const { TEST_SNAPS_WEBSITE_URL } = require('./enums');
describe('Test Snap Confirm', function () { describe('Test Snap Installed', function () {
it('can pop up a snap confirm and get its result', async function () { it('can tell if a snap is installed', async function () {
const ganacheOptions = { const ganacheOptions = {
accounts: [ accounts: [
{ {
@ -16,10 +16,9 @@ describe('Test Snap Confirm', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -30,13 +29,32 @@ describe('Test Snap Confirm', function () {
await driver.press('#password', driver.Key.ENTER); await driver.press('#password', driver.Key.ENTER);
// navigate to test snaps page and connect // navigate to test snaps page and connect
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
await driver.fill('#snapId1', 'npm:@metamask/test-snap-confirm'); await driver.delay(1000);
await driver.clickElement('#connectHello'); const confirmButton = await driver.findElement('#connectConfirmSnap');
await driver.scrollToElement(confirmButton);
await driver.clickElement('#connectConfirmSnap');
// switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(3, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap // approve install of snap
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(3, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
@ -47,18 +65,33 @@ describe('Test Snap Confirm', function () {
}); });
// click send inputs on test snap page // click send inputs on test snap page
await driver.waitUntilXWindowHandles(1, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
const errorButton = await driver.findElement('#connectError'); const errorButton = await driver.findElement('#connectErrorSnap');
await driver.scrollToElement(errorButton); await driver.scrollToElement(errorButton);
await driver.delay(1000); await driver.delay(1000);
await driver.fill('#snapId2', 'npm:@metamask/test-snap-error'); await driver.clickElement('#connectErrorSnap');
await driver.clickElement('#connectError');
// switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(3, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap // approve install of snap
await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
@ -69,19 +102,13 @@ describe('Test Snap Confirm', function () {
tag: 'button', tag: 'button',
}); });
await driver.waitUntilXWindowHandles(1, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
const getInstalledSnapsButton = await driver.findElement( const result = await driver.findElement('#installedSnapsResult');
'#getInstalledSnapsButton', await driver.scrollToElement(result);
);
await driver.scrollToElement(getInstalledSnapsButton);
await driver.delay(1000); await driver.delay(1000);
await driver.clickElement('#getInstalledSnapsButton');
await driver.delay(1000);
const result = await driver.findElement('#getInstalledSnapsResult');
assert.equal( assert.equal(
await result.getText(), await result.getText(),
'npm:@metamask/test-snap-confirm, npm:@metamask/test-snap-error', 'npm:@metamask/test-snap-confirm, npm:@metamask/test-snap-error',

View File

@ -17,10 +17,9 @@ describe('Test Snap manageState', function () {
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -31,32 +30,45 @@ describe('Test Snap manageState', function () {
await driver.press('#password', driver.Key.ENTER); await driver.press('#password', driver.Key.ENTER);
// navigate to test snaps page, then fill in the snapId // navigate to test snaps page, then fill in the snapId
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
await driver.delay(1000); await driver.delay(1000);
await driver.fill('#snapId4', 'npm:@metamask/test-snap-managestate');
// find and scroll to the rest of the card // find and scroll to the connect button and click it
const snapButton = await driver.findElement('#snapId4'); const snapButton1 = await driver.findElement('#connectManageState');
await driver.scrollToElement(snapButton); await driver.scrollToElement(snapButton1);
await driver.delay(500); await driver.delay(1000);
// connect the snap
await driver.clickElement('#connectManageState'); await driver.clickElement('#connectManageState');
// approve install of snap // switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(3, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles(); let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
); );
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap
await driver.waitUntilXWindowHandles(3, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ await driver.clickElement({
text: 'Approve & install', text: 'Approve & install',
tag: 'button', tag: 'button',
}); });
// fill and click send inputs on test snap page // fill and click send inputs on test snap page
await driver.waitUntilXWindowHandles(1, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.fill('#dataManageState', '23'); await driver.fill('#dataManageState', '23');
@ -64,46 +76,40 @@ describe('Test Snap manageState', function () {
await driver.clickElement('#sendManageState'); await driver.clickElement('#sendManageState');
// check the results of the public key test // check the results of the public key test
await driver.delay(500); await driver.delay(1000);
const manageStateResult = await driver.findElement( const manageStateResult = await driver.findElement(
'#sendManageStateResult', '#sendManageStateResult',
); );
assert.equal(await manageStateResult.getText(), 'true'); assert.equal(await manageStateResult.getText(), 'true');
// click get results
await driver.clickElement('#retrieveManageState');
// check the results // check the results
await driver.delay(500); await driver.delay(1000);
const retrieveManageStateResult = await driver.findElement( const retrieveManageStateResult = await driver.findElement(
'#retrieveManageStateResult', '#retrieveManageStateResult',
); );
assert.equal( assert.equal(
await retrieveManageStateResult.getText(), await retrieveManageStateResult.getText(),
'{"testState":["23"]}', '{ "testState": [ "23" ] }',
); );
// click clear results // click clear results
await driver.clickElement('#clearManageState'); await driver.clickElement('#clearManageState');
// check if true // check if true
await driver.delay(500); await driver.delay(1000);
const clearManageStateResult = await driver.findElement( const clearManageStateResult = await driver.findElement(
'#clearManageStateResult', '#clearManageStateResult',
); );
assert.equal(await clearManageStateResult.getText(), 'true'); assert.equal(await clearManageStateResult.getText(), 'true');
// click get results again
await driver.clickElement('#retrieveManageState');
// check result array is empty // check result array is empty
await driver.delay(500); await driver.delay(1000);
const retrieveManageStateResult2 = await driver.findElement( const retrieveManageStateResult2 = await driver.findElement(
'#retrieveManageStateResult', '#retrieveManageStateResult',
); );
assert.equal( assert.equal(
await retrieveManageStateResult2.getText(), await retrieveManageStateResult2.getText(),
'{"testState":[]}', '{ "testState": [] }',
); );
}, },
); );

View File

@ -1,6 +1,5 @@
const { strict: assert } = require('assert'); const { strict: assert } = require('assert');
const { withFixtures } = require('../helpers'); const { withFixtures } = require('../helpers');
const { PAGES } = require('../webdriver/driver');
const FixtureBuilder = require('../fixture-builder'); const FixtureBuilder = require('../fixture-builder');
const { TEST_SNAPS_WEBSITE_URL } = require('./enums'); const { TEST_SNAPS_WEBSITE_URL } = require('./enums');
@ -17,10 +16,9 @@ describe('Test Snap Notification', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -31,21 +29,35 @@ describe('Test Snap Notification', function () {
await driver.press('#password', driver.Key.ENTER); await driver.press('#password', driver.Key.ENTER);
// navigate to test snaps page // navigate to test snaps page
await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
await driver.delay(1000); await driver.delay(1000);
// find and scroll down to snapId5 // find and scroll down to snapId5 and connect
const snapButton = await driver.findElement('#snapId5'); const snapButton = await driver.findElement('#connectNotification');
await driver.scrollToElement(snapButton); await driver.scrollToElement(snapButton);
await driver.delay(500); await driver.delay(500);
await driver.fill('#snapId5', 'npm:@metamask/test-snap-notification');
// connect the snap
await driver.clickElement('#connectNotification'); await driver.clickElement('#connectNotification');
// approve install of snap // switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(2, 5000, 10000); await driver.waitUntilXWindowHandles(3, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles(); let windowHandles = await driver.getAllWindowHandles();
const extensionPage = windowHandles[0];
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap
await driver.waitUntilXWindowHandles(3, 5000, 10000);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
@ -56,14 +68,14 @@ describe('Test Snap Notification', function () {
}); });
// click send inputs on test snap page // click send inputs on test snap page
await driver.waitUntilXWindowHandles(1, 5000, 10000); await driver.waitUntilXWindowHandles(2, 5000, 10000);
windowHandles = await driver.getAllWindowHandles(); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles); await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000); await driver.delay(1000);
await driver.clickElement('#sendInAppNotification'); await driver.clickElement('#sendInAppNotification');
// try to go to the MM pages // switch back to the extension page
await driver.navigate(PAGES.HOME); await driver.switchToWindow(extensionPage);
await driver.delay(1500); await driver.delay(1500);
// check to see that there is one notification // check to see that there is one notification
@ -74,14 +86,14 @@ describe('Test Snap Notification', function () {
// try to click on the account menu icon (via xpath) // try to click on the account menu icon (via xpath)
await driver.clickElement('.account-menu__icon'); await driver.clickElement('.account-menu__icon');
await driver.delay(500); await driver.delay(1000);
// try to click on the notification item (via xpath) // try to click on the notification item (via xpath)
await driver.clickElement({ await driver.clickElement({
text: 'Notifications', text: 'Notifications',
tag: 'div', tag: 'div',
}); });
await driver.delay(500); await driver.delay(1000);
// look for the correct text in notifications (via xpath) // look for the correct text in notifications (via xpath)
const notificationResultMessage = await driver.findElement( const notificationResultMessage = await driver.findElement(

View File

@ -16,10 +16,9 @@ describe('Test Snap update', function () {
}; };
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder() fixtures: new FixtureBuilder().build(),
.withPermissionControllerConnectedToSnapDapp()
.build(),
ganacheOptions, ganacheOptions,
failOnConsoleError: false,
title: this.test.title, title: this.test.title,
}, },
async ({ driver }) => { async ({ driver }) => {
@ -33,15 +32,32 @@ describe('Test Snap update', function () {
await driver.openNewPage(TEST_SNAPS_WEBSITE_URL); await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
// find and scroll to the correct card and click first // find and scroll to the correct card and click first
const snapButton = await driver.findElement('#sendUpdateHello'); const snapButton = await driver.findElement('#connectUpdateNew');
await driver.scrollToElement(snapButton); await driver.scrollToElement(snapButton);
await driver.delay(500); await driver.delay(1000);
await driver.fill('#snapId7', 'npm:@metamask/test-snap-confirm'); await driver.clickElement('#connectUpdate');
await driver.clickElement('#connectUpdateOld');
await driver.delay(2000);
// switch to metamask extension and click connect
await driver.waitUntilXWindowHandles(3, 5000, 10000);
let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement(
{
text: 'Connect',
tag: 'button',
},
10000,
);
await driver.delay(2000);
// approve install of snap // approve install of snap
let windowHandles = await driver.getAllWindowHandles(); await driver.waitUntilXWindowHandles(3, 5000, 10000);
const extensionPage = windowHandles[0]; windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(
'MetaMask Notification', 'MetaMask Notification',
windowHandles, windowHandles,
@ -58,9 +74,9 @@ describe('Test Snap update', function () {
await driver.delay(1000); await driver.delay(1000);
// find and scroll to the correct card and click first // find and scroll to the correct card and click first
const snapButton2 = await driver.findElement('#snapId7'); const snapButton2 = await driver.findElement('#connectUpdateNew');
await driver.scrollToElement(snapButton2); await driver.scrollToElement(snapButton2);
await driver.delay(500); await driver.delay(1000);
await driver.clickElement('#connectUpdateNew'); await driver.clickElement('#connectUpdateNew');
// switch to metamask extension and click connect // switch to metamask extension and click connect
@ -78,33 +94,15 @@ describe('Test Snap update', function () {
tag: 'button', tag: 'button',
}); });
// switch to the original MM tab // navigate to test snap page
await driver.switchToWindow(extensionPage); await driver.waitUntilXWindowHandles(2, 5000, 10000);
await driver.delay(500); windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
// click on the account menu icon
await driver.clickElement('.account-menu__icon');
await driver.delay(500);
// try to click on the notification item
await driver.clickElement({
text: 'Settings',
tag: 'div',
});
await driver.delay(500);
// try to click on the snaps item
await driver.clickElement({
text: 'Snaps',
tag: 'div',
});
await driver.delay(500);
// look for the correct version text // look for the correct version text
const versionResult = await driver.findElement( const versionResult = await driver.findElement('#updateSnapVersion');
'.snap-settings-card__version', await driver.delay(1000);
); assert.equal(await versionResult.getText(), '"2.0.0"');
assert.equal(await versionResult.getText(), 'v2.0.0');
}, },
); );
}); });