From 0e82a3c35c228cca6ea069bedafd2ce2135dcf14 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 28 Feb 2024 17:37:47 +0500 Subject: [PATCH 1/4] feature: adding keplr interaction for creating an account using private key --- commands/keplr.js | 77 +++++++++++++++++++++-------- commands/playwright-keplr.js | 30 ++++++++--- pages/keplr/first-time-flow-page.js | 2 + plugins/keplr-plugin.js | 1 + support/commands.js | 4 ++ tests/e2e/specs/keplr/keplr-spec.js | 39 ++++++++------- 6 files changed, 108 insertions(+), 45 deletions(-) diff --git a/commands/keplr.js b/commands/keplr.js index 1f7dca9a8..ae7dddda5 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -48,6 +48,43 @@ const keplr = { onboardingElements.useRecoveryPhraseButton, await playwright.keplrWindow(), ); + + if (secretWords.includes(' ')) { + await module.exports.importWalletWithPhrase(secretWords, password); + } else { + await module.exports.importWalletWithPrivateKey(secretWords, password); + } + + await playwright.waitAndClick( + onboardingElements.submitWalletDataButton, + await playwright.keplrWindow(), + { number: 1 }, + ); + + await playwright.waitForByText( + onboardingElements.phraseSelectChain, + await playwright.keplrWindow(), + ); + + await playwright.waitAndClick( + onboardingElements.submitChainButton, + await playwright.keplrWindow(), + ); + + await playwright.waitForByText( + onboardingElements.phraseAccountCreated, + await playwright.keplrWindow(), + ); + + await playwright.waitAndClick( + onboardingElements.finishButton, + await playwright.keplrWindow(), + { dontWait: true }, + ); + + return true; + }, + async importWalletWithPhrase(secretWords, password) { await playwright.waitAndClickByText( onboardingElements.phraseCount24, await playwright.keplrWindow(), @@ -75,37 +112,37 @@ const keplr = { onboardingElements.confirmPasswordInput, password, ); + }, + async importWalletWithPrivateKey(privateKey, password) { + await playwright.clickByText(onboardingElements.phrasePrivateKey); - await playwright.waitAndClick( - onboardingElements.submitWalletDataButton, - await playwright.keplrWindow(), - { number: 1 }, - ); - - await playwright.waitForByText( - onboardingElements.phraseSelectChain, - await playwright.keplrWindow(), + await playwright.waitAndTypeByLocator( + onboardingElements.textAreaSelector, + privateKey, ); await playwright.waitAndClick( - onboardingElements.submitChainButton, + onboardingElements.submitPhraseButton, await playwright.keplrWindow(), ); - await playwright.waitForByText( - onboardingElements.phraseAccountCreated, - await playwright.keplrWindow(), + await playwright.waitAndType( + onboardingElements.walletInput, + onboardingElements.walletName, ); - await playwright.waitAndClick( - onboardingElements.finishButton, - await playwright.keplrWindow(), - { dontWait: true }, + const passwordFieldExists = await playwright.doesElementExist( + onboardingElements.passwordInput, ); - return true; + if (passwordFieldExists) { + await playwright.waitAndType(onboardingElements.passwordInput, password); + await playwright.waitAndType( + onboardingElements.confirmPasswordInput, + password, + ); + } }, - async acceptAccess() { const notificationPage = await playwright.switchToKeplrNotification(); await playwright.waitAndClick( @@ -143,4 +180,4 @@ const keplr = { }, }; -module.exports = keplr; \ No newline at end of file +module.exports = keplr; diff --git a/commands/playwright-keplr.js b/commands/playwright-keplr.js index c7fc975c6..722bc90e2 100644 --- a/commands/playwright-keplr.js +++ b/commands/playwright-keplr.js @@ -7,6 +7,7 @@ let browser; let mainWindow; let keplrWindow; let keplrNotificationWindow; +let keplrRegistrationWindow; let activeTabName; let extensionsData = {}; let retries = 0; @@ -19,6 +20,7 @@ module.exports = { keplrWindow = undefined; activeTabName = undefined; keplrNotificationWindow = undefined; + keplrRegistrationWindow = undefined; retries = 0; extensionsData = {}; }, @@ -77,6 +79,10 @@ module.exports = { return keplrNotificationWindow; }, + async clickByText(text, page = keplrWindow) { + await page.click(`text="${text}"`); + }, + async waitAndClickByText(text, page = keplrWindow) { await module.exports.waitForByText(text, page); const element = `:is(:text-is("${text}"), :text("${text}"))`; @@ -170,16 +176,13 @@ module.exports = { }, async waitUntilStable(page) { - const keplrExtensionData = (await module.exports.getExtensionsData()) - .keplr; + const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; if ( page && page .url() - .includes( - `chrome-extension://${keplrExtensionData.id}/register.html`, - ) + .includes(`chrome-extension://${keplrExtensionData.id}/register.html`) ) { await page.waitForLoadState('load'); await page.waitForLoadState('domcontentloaded'); @@ -216,6 +219,14 @@ module.exports = { } return element; }, + async doesElementExist(selector, timeout = 1000, page = keplrWindow) { + try { + await page.waitForSelector(selector, { timeout }); + return true; + } catch (error) { + return false; + } + }, async waitForByText(text, page = keplrWindow) { await module.exports.waitUntilStable(page); // await page.waitForSelector(selector, { strict: false }); @@ -347,6 +358,13 @@ module.exports = { return extensionsData; }, + async switchToKeplrRegistrationWindow() { + const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; + const browserContext = await browser.contexts()[0]; + keplrRegistrationWindow = await browserContext.newPage(); + await keplrRegistrationWindow.goto(`chrome-extension://${keplrExtensionData.id}/register.html`); + return true; + }, async switchToKeplrNotification() { const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; @@ -375,4 +393,4 @@ module.exports = { ); } }, -}; \ No newline at end of file +}; diff --git a/pages/keplr/first-time-flow-page.js b/pages/keplr/first-time-flow-page.js index d79d6e7f9..786d5c428 100644 --- a/pages/keplr/first-time-flow-page.js +++ b/pages/keplr/first-time-flow-page.js @@ -2,6 +2,7 @@ const createWalletButton = 'Create a new wallet'; const importRecoveryPhraseButton = 'Import existing recovery phrase'; const useRecoveryPhraseButton = 'Use recovery phrase or private key'; const phraseCount24 = '24 words'; +const phrasePrivateKey = 'Private key'; const walletInput = 'input[name="name"]:focus'; const passwordInput = 'input[name="password"]'; const confirmPasswordInput = 'input[name="confirmPassword"]'; @@ -19,6 +20,7 @@ module.exports.onboardingElements = { importRecoveryPhraseButton, useRecoveryPhraseButton, phraseCount24, + phrasePrivateKey, walletInput, walletName, passwordInput, diff --git a/plugins/keplr-plugin.js b/plugins/keplr-plugin.js index 99ef9be15..96d07b169 100644 --- a/plugins/keplr-plugin.js +++ b/plugins/keplr-plugin.js @@ -59,6 +59,7 @@ module.exports = (on, config) => { clearWindows: playwright.clearWindows, isCypressWindowActive: playwright.isCypressWindowActive, switchToExtensionWindow: playwright.switchToKeplrWindow, + switchToExtensionRegistrationWindow: playwright.switchToKeplrRegistrationWindow, // keplr commands importWallet: keplr.importWallet, diff --git a/support/commands.js b/support/commands.js index 1c5363a62..d357a6748 100644 --- a/support/commands.js +++ b/support/commands.js @@ -437,4 +437,8 @@ Cypress.Commands.add('isExtensionWindowActive', () => { Cypress.Commands.add('switchToExtensionWindow', () => { return cy.task('switchToExtensionWindow'); +}); + +Cypress.Commands.add('switchToExtensionRegistrationWindow', () => { + return cy.task('switchToExtensionRegistrationWindow'); }); \ No newline at end of file diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index 28e5b3049..5c11b5b56 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -1,30 +1,31 @@ /* eslint-disable ui-testing/no-disabled-tests */ describe('Keplr', () => { - context('Test commands', () => { - it(`setupWallet should finish Keplr setup using secret words`, () => { - cy.setupWallet().then(setupFinished => { - expect(setupFinished).to.be.true; - }); - }); - - it(`acceptAccess should accept connection request to Keplr`, () => { + context('Test commands', () => { + it(`should complete Keplr connect with wallet, and confirm transaction after importing a wallet using 24 word phrase`, () => { + cy.setupWallet().then(setupFinished => { + expect(setupFinished).to.be.true; + cy.visit('/'); cy.contains('Connect Wallet').click(); cy.acceptAccess().then(taskCompleted => { expect(taskCompleted).to.be.true; + + cy.contains('Make an Offer').click(); + cy.confirmTransaction().then(taskCompleted => { + expect(taskCompleted).to.be.true; + }); }); - cy.get('.card') - .contains('My Wallet') - .then(p => console.log(p)); - - cy.contains('agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md'); }); - - it(`confirmTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { - cy.contains('Make an Offer').click(); - cy.confirmTransaction().then(taskCompleted => { - expect(taskCompleted).to.be.true; + }); + + it(`should complete Keplr setup by importing the wallet using private key`, () => { + cy.switchToExtensionRegistrationWindow().then(() => { + cy.setupWallet( + 'A9C09B6E4AF70DE1F1B621CB1AA66CFD0B4AA977E4C18497C49132DD9E579485', + ).then(setupFinished => { + expect(setupFinished).to.be.true; }); }); }); - }); \ No newline at end of file + }); +}); From e48a42b4a9a10de27b896f9998b0a4fa81fd4c40 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 28 Feb 2024 22:09:11 +0500 Subject: [PATCH 2/4] feature: keplr interaction for importing an existing wallet and creating a new wallet --- commands/keplr.js | 77 +++++++++++++++-------------- pages/keplr/first-time-flow-page.js | 4 +- plugins/keplr-plugin.js | 8 +-- support/commands.js | 4 +- tests/e2e/specs/keplr/keplr-spec.js | 25 +++++++++- 5 files changed, 71 insertions(+), 47 deletions(-) diff --git a/commands/keplr.js b/commands/keplr.js index ae7dddda5..978703747 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -35,26 +35,50 @@ const keplr = { }; }, - async importWallet(secretWords, password) { + async importWallet(secretWords, password, newAccount) { await playwright.waitAndClickByText( - onboardingElements.createWalletButton, - await playwright.keplrWindow(), - ); - await playwright.waitAndClickByText( - onboardingElements.importRecoveryPhraseButton, + newAccount + ? onboardingElements.createWalletButton + : onboardingElements.existingWalletButton, await playwright.keplrWindow(), ); + await playwright.waitAndClickByText( - onboardingElements.useRecoveryPhraseButton, + newAccount + ? onboardingElements.importRecoveryPhraseButton + : onboardingElements.useRecoveryPhraseButton, await playwright.keplrWindow(), ); + newAccount && + (await playwright.waitAndClickByText( + onboardingElements.useRecoveryPhraseButton, + await playwright.keplrWindow(), + )); + if (secretWords.includes(' ')) { await module.exports.importWalletWithPhrase(secretWords, password); } else { await module.exports.importWalletWithPrivateKey(secretWords, password); } + await playwright.waitAndType( + onboardingElements.walletInput, + onboardingElements.walletName, + ); + + const passwordFieldExists = await playwright.doesElementExist( + onboardingElements.passwordInput, + ); + + if (passwordFieldExists) { + await playwright.waitAndType(onboardingElements.passwordInput, password); + await playwright.waitAndType( + onboardingElements.confirmPasswordInput, + password, + ); + } + await playwright.waitAndClick( onboardingElements.submitWalletDataButton, await playwright.keplrWindow(), @@ -84,7 +108,7 @@ const keplr = { return true; }, - async importWalletWithPhrase(secretWords, password) { + async importWalletWithPhrase(secretWords) { await playwright.waitAndClickByText( onboardingElements.phraseCount24, await playwright.keplrWindow(), @@ -102,18 +126,8 @@ const keplr = { onboardingElements.submitPhraseButton, await playwright.keplrWindow(), ); - - await playwright.waitAndType( - onboardingElements.walletInput, - onboardingElements.walletName, - ); - await playwright.waitAndType(onboardingElements.passwordInput, password); - await playwright.waitAndType( - onboardingElements.confirmPasswordInput, - password, - ); }, - async importWalletWithPrivateKey(privateKey, password) { + async importWalletWithPrivateKey(privateKey) { await playwright.clickByText(onboardingElements.phrasePrivateKey); await playwright.waitAndTypeByLocator( @@ -125,23 +139,6 @@ const keplr = { onboardingElements.submitPhraseButton, await playwright.keplrWindow(), ); - - await playwright.waitAndType( - onboardingElements.walletInput, - onboardingElements.walletName, - ); - - const passwordFieldExists = await playwright.doesElementExist( - onboardingElements.passwordInput, - ); - - if (passwordFieldExists) { - await playwright.waitAndType(onboardingElements.passwordInput, password); - await playwright.waitAndType( - onboardingElements.confirmPasswordInput, - password, - ); - } }, async acceptAccess() { const notificationPage = await playwright.switchToKeplrNotification(); @@ -165,7 +162,7 @@ const keplr = { async initialSetup( playwrightInstance, - { secretWordsOrPrivateKey, password }, + { secretWordsOrPrivateKey, password, newAccount }, ) { if (playwrightInstance) { await playwright.init(playwrightInstance); @@ -176,7 +173,11 @@ const keplr = { await playwright.assignWindows(); await playwright.assignActiveTabName('keplr'); await module.exports.getExtensionDetails(); - await module.exports.importWallet(secretWordsOrPrivateKey, password); + await module.exports.importWallet( + secretWordsOrPrivateKey, + password, + newAccount, + ); }, }; diff --git a/pages/keplr/first-time-flow-page.js b/pages/keplr/first-time-flow-page.js index 786d5c428..7bfc1bf52 100644 --- a/pages/keplr/first-time-flow-page.js +++ b/pages/keplr/first-time-flow-page.js @@ -1,5 +1,6 @@ const createWalletButton = 'Create a new wallet'; -const importRecoveryPhraseButton = 'Import existing recovery phrase'; +const existingWalletButton = 'Import an existing wallet'; +const importRecoveryPhraseButton = 'Import existing recovery phrase'; const useRecoveryPhraseButton = 'Use recovery phrase or private key'; const phraseCount24 = '24 words'; const phrasePrivateKey = 'Private key'; @@ -16,6 +17,7 @@ const textAreaSelector = 'textbox'; const submitPhraseButton = 'button[type="submit"]'; module.exports.onboardingElements = { + existingWalletButton, createWalletButton, importRecoveryPhraseButton, useRecoveryPhraseButton, diff --git a/plugins/keplr-plugin.js b/plugins/keplr-plugin.js index 96d07b169..2d018276c 100644 --- a/plugins/keplr-plugin.js +++ b/plugins/keplr-plugin.js @@ -67,17 +67,13 @@ module.exports = (on, config) => { confirmTransaction: keplr.confirmTransaction, setupWallet: async ({ secretWordsOrPrivateKey, - network, password, - enableAdvancedSettings, - enableExperimentalSettings, + newAccount, }) => { await keplr.initialSetup(null, { secretWordsOrPrivateKey, - network, password, - enableAdvancedSettings, - enableExperimentalSettings, + newAccount }); return true; }, diff --git a/support/commands.js b/support/commands.js index d357a6748..0dac7f6a2 100644 --- a/support/commands.js +++ b/support/commands.js @@ -415,10 +415,12 @@ Cypress.Commands.add( ( secretWordsOrPrivateKey = 'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology', password = 'Test1234', + newAccount = false ) => { return cy.task('setupWallet', { secretWordsOrPrivateKey, - password + password, + newAccount }); }, ); diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index 5c11b5b56..fb7588bb6 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -1,7 +1,7 @@ /* eslint-disable ui-testing/no-disabled-tests */ describe('Keplr', () => { context('Test commands', () => { - it(`should complete Keplr connect with wallet, and confirm transaction after importing a wallet using 24 word phrase`, () => { + it(`should complete Keplr connect with wallet, and confirm transaction after importing an existing wallet using 24 word phrase`, () => { cy.setupWallet().then(setupFinished => { expect(setupFinished).to.be.true; @@ -18,6 +18,29 @@ describe('Keplr', () => { }); }); + it(`should complete Keplr connect with wallet, and confirm transaction after creating a new wallet using 24 word phrase`, () => { + cy.switchToExtensionRegistrationWindow().then(() => { + cy.setupWallet( + 'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology', + 'Test1234', + true, + ).then(setupFinished => { + expect(setupFinished).to.be.true; + + cy.visit('/'); + cy.contains('Connect Wallet').click(); + cy.acceptAccess().then(taskCompleted => { + expect(taskCompleted).to.be.true; + + cy.contains('Make an Offer').click(); + cy.confirmTransaction().then(taskCompleted => { + expect(taskCompleted).to.be.true; + }); + }); + }); + }); + }); + it(`should complete Keplr setup by importing the wallet using private key`, () => { cy.switchToExtensionRegistrationWindow().then(() => { cy.setupWallet( From 5543a632115ef131aa621f640b4ba094a6783307 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Thu, 29 Feb 2024 15:10:30 +0500 Subject: [PATCH 3/4] chore: handling an edge when user is already connected to the wallet --- commands/keplr.js | 27 +++++++++++++++++++++++---- commands/playwright-keplr.js | 17 ++++++++++++----- support/commands.js | 10 +++++++++- tests/e2e/specs/keplr/keplr-spec.js | 16 ++++------------ 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/commands/keplr.js b/commands/keplr.js index 978703747..98ed4d8b3 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -141,20 +141,39 @@ const keplr = { ); }, async acceptAccess() { - const notificationPage = await playwright.switchToKeplrNotification(); + const result = await playwright.switchToKeplrNotification(); + + if ( + result.err && + result.message === 'Unable to Switch to Notification Window' + ) { + let pages = await playwright.browser().contexts()[0].pages(); + + for (const page of pages) { + const pageContent = await page.textContent('html'); + if ( + pageContent.includes('agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md') + ) { + return true; + } + } + + return false; + } + await playwright.waitAndClick( notificationPageElements.approveButton, - notificationPage, + result.page, { waitForEvent: 'close' }, ); return true; }, async confirmTransaction() { - const notificationPage = await playwright.switchToKeplrNotification(); + const result = await playwright.switchToKeplrNotification(); await playwright.waitAndClick( notificationPageElements.approveButton, - notificationPage, + result.page, { waitForEvent: 'close' }, ); return true; diff --git a/commands/playwright-keplr.js b/commands/playwright-keplr.js index 722bc90e2..12d7e8b71 100644 --- a/commands/playwright-keplr.js +++ b/commands/playwright-keplr.js @@ -79,6 +79,10 @@ module.exports = { return keplrNotificationWindow; }, + browser() { + return browser; + }, + async clickByText(text, page = keplrWindow) { await page.click(`text="${text}"`); }, @@ -362,7 +366,9 @@ module.exports = { const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; const browserContext = await browser.contexts()[0]; keplrRegistrationWindow = await browserContext.newPage(); - await keplrRegistrationWindow.goto(`chrome-extension://${keplrExtensionData.id}/register.html`); + await keplrRegistrationWindow.goto( + `chrome-extension://${keplrExtensionData.id}/register.html`, + ); return true; }, async switchToKeplrNotification() { @@ -379,7 +385,7 @@ module.exports = { retries = 0; await page.bringToFront(); await module.exports.waitUntilStable(page); - return page; + return { page, err: false }; } } await sleep(200); @@ -388,9 +394,10 @@ module.exports = { return await module.exports.switchToKeplrNotification(); } else if (retries >= 50) { retries = 0; - throw new Error( - '[switchToKeplrNotification] Max amount of retries to switch to keplr notification window has been reached. It was never found.', - ); + return { + err: true, + message: 'Unable to Switch to Notification Window', + }; } }, }; diff --git a/support/commands.js b/support/commands.js index 0dac7f6a2..072e9959d 100644 --- a/support/commands.js +++ b/support/commands.js @@ -443,4 +443,12 @@ Cypress.Commands.add('switchToExtensionWindow', () => { Cypress.Commands.add('switchToExtensionRegistrationWindow', () => { return cy.task('switchToExtensionRegistrationWindow'); -}); \ No newline at end of file +}); + +Cypress.Commands.add('makeOfferAndConfirmTransaction', () => { + cy.contains('agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md'); + cy.contains('Make an Offer').click(); + return cy.confirmTransaction().then(taskCompleted => { + expect(taskCompleted).to.be.true; + }); +}); diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index fb7588bb6..fff79e212 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -1,7 +1,7 @@ /* eslint-disable ui-testing/no-disabled-tests */ describe('Keplr', () => { context('Test commands', () => { - it(`should complete Keplr connect with wallet, and confirm transaction after importing an existing wallet using 24 word phrase`, () => { + it(`should connect with wallet, and confirm transaction after importing an existing wallet using 24 word phrase`, () => { cy.setupWallet().then(setupFinished => { expect(setupFinished).to.be.true; @@ -9,16 +9,12 @@ describe('Keplr', () => { cy.contains('Connect Wallet').click(); cy.acceptAccess().then(taskCompleted => { expect(taskCompleted).to.be.true; - - cy.contains('Make an Offer').click(); - cy.confirmTransaction().then(taskCompleted => { - expect(taskCompleted).to.be.true; - }); + cy.makeOfferAndConfirmTransaction(); }); }); }); - it(`should complete Keplr connect with wallet, and confirm transaction after creating a new wallet using 24 word phrase`, () => { + it(`should connect with wallet, and confirm transaction after creating a new wallet using 24 word phrase`, () => { cy.switchToExtensionRegistrationWindow().then(() => { cy.setupWallet( 'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology', @@ -31,11 +27,7 @@ describe('Keplr', () => { cy.contains('Connect Wallet').click(); cy.acceptAccess().then(taskCompleted => { expect(taskCompleted).to.be.true; - - cy.contains('Make an Offer').click(); - cy.confirmTransaction().then(taskCompleted => { - expect(taskCompleted).to.be.true; - }); + cy.makeOfferAndConfirmTransaction(); }); }); }); From d67fbfe6688bb0366dac37a26164dfd8f2bee49c Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 1 Mar 2024 11:19:22 +0500 Subject: [PATCH 4/4] feature: keplr intereaction for disconnecting with wallet --- commands/keplr.js | 8 ++++++++ commands/playwright-keplr.js | 19 ++++++++++++++++++- plugins/keplr-plugin.js | 2 ++ support/commands.js | 8 ++++++++ tests/e2e/specs/keplr/keplr-spec.js | 8 ++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/commands/keplr.js b/commands/keplr.js index 98ed4d8b3..81c3f5f2e 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -179,6 +179,14 @@ const keplr = { return true; }, + async disconnectWallet() { + await playwright.clickByText( + 'Disconnect All', + playwright.keplrPermissionWindow(), + ); + return true; + }, + async initialSetup( playwrightInstance, { secretWordsOrPrivateKey, password, newAccount }, diff --git a/commands/playwright-keplr.js b/commands/playwright-keplr.js index 12d7e8b71..42728efde 100644 --- a/commands/playwright-keplr.js +++ b/commands/playwright-keplr.js @@ -8,6 +8,7 @@ let mainWindow; let keplrWindow; let keplrNotificationWindow; let keplrRegistrationWindow; +let keplrPermissionWindow; let activeTabName; let extensionsData = {}; let retries = 0; @@ -21,6 +22,7 @@ module.exports = { activeTabName = undefined; keplrNotificationWindow = undefined; keplrRegistrationWindow = undefined; + keplrPermissionWindow = undefined; retries = 0; extensionsData = {}; }, @@ -29,7 +31,7 @@ module.exports = { const chromium = playwrightInstance ? playwrightInstance : require('@playwright/test').chromium; - const debuggerDetails = await fetch('http://127.0.0.1:9222/json/version'); //DevSkim: ignore DS137138 + const debuggerDetails = await fetch('http://127.0.0.1:9222/json/version'); const debuggerDetailsConfig = await debuggerDetails.json(); const webSocketDebuggerUrl = debuggerDetailsConfig.webSocketDebuggerUrl; if (process.env.SLOW_MODE) { @@ -362,6 +364,20 @@ module.exports = { return extensionsData; }, + keplrPermissionWindow() { + return keplrPermissionWindow; + }, + + async switchToKeplrPermissionWindow() { + const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; + const browserContext = await browser.contexts()[0]; + keplrPermissionWindow = await browserContext.newPage(); + await keplrPermissionWindow.goto( + `chrome-extension://${keplrExtensionData.id}/popup.html#/setting/security/permission`, + ); + return true; + }, + async switchToKeplrRegistrationWindow() { const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; const browserContext = await browser.contexts()[0]; @@ -371,6 +387,7 @@ module.exports = { ); return true; }, + async switchToKeplrNotification() { const keplrExtensionData = (await module.exports.getExtensionsData()).keplr; diff --git a/plugins/keplr-plugin.js b/plugins/keplr-plugin.js index 2d018276c..7890683cd 100644 --- a/plugins/keplr-plugin.js +++ b/plugins/keplr-plugin.js @@ -60,11 +60,13 @@ module.exports = (on, config) => { isCypressWindowActive: playwright.isCypressWindowActive, switchToExtensionWindow: playwright.switchToKeplrWindow, switchToExtensionRegistrationWindow: playwright.switchToKeplrRegistrationWindow, + switchToExtensionPermissionWindow: playwright.switchToKeplrPermissionWindow, // keplr commands importWallet: keplr.importWallet, acceptAccess: keplr.acceptAccess, confirmTransaction: keplr.confirmTransaction, + disconnectWallet: keplr.disconnectWallet, setupWallet: async ({ secretWordsOrPrivateKey, password, diff --git a/support/commands.js b/support/commands.js index 072e9959d..57616301e 100644 --- a/support/commands.js +++ b/support/commands.js @@ -445,6 +445,14 @@ Cypress.Commands.add('switchToExtensionRegistrationWindow', () => { return cy.task('switchToExtensionRegistrationWindow'); }); +Cypress.Commands.add('switchToExtensionPermissionWindow', () => { + return cy.task('switchToExtensionPermissionWindow'); +}); + +Cypress.Commands.add('disconnectWallet', () => { + return cy.task('disconnectWallet'); +}); + Cypress.Commands.add('makeOfferAndConfirmTransaction', () => { cy.contains('agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md'); cy.contains('Make an Offer').click(); diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index fff79e212..2a109dc8b 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -33,6 +33,14 @@ describe('Keplr', () => { }); }); + it(`should disconnect the wallet from all the connected DAPPs`, () => { + cy.switchToExtensionPermissionWindow().then(() => { + cy.disconnectWallet().then(taskCompleted => { + expect(taskCompleted).to.be.true; + }); + }); + }); + it(`should complete Keplr setup by importing the wallet using private key`, () => { cy.switchToExtensionRegistrationWindow().then(() => { cy.setupWallet(