From 6e8fd1306e501b00ce1f846b02f752cb4d41b026 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 1 Mar 2024 15:49:43 +0500 Subject: [PATCH] feature: adding intereaction for disconnecting with wallet --- commands/keplr.js | 9 ++++++++- commands/playwright-keplr.js | 16 ++++++++++++++++ plugins/keplr-plugin.js | 2 ++ support/commands.js | 8 ++++++++ tests/e2e/specs/keplr/keplr-spec.js | 9 +++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/commands/keplr.js b/commands/keplr.js index 891293fa5..15f240b58 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -34,7 +34,14 @@ const keplr = { extensionVersion, }; }, - + async disconnectWalletFromDapp() { + await playwright.waitAndClickByText( + 'Disconnect All', + playwright.keplrPermissionWindow(), + exact = false, + ); + return true; + }, async importWallet(secretWordsOrPrivateKey, password, newAccount) { await playwright.waitAndClickByText( newAccount diff --git a/commands/playwright-keplr.js b/commands/playwright-keplr.js index 0d953b3db..4f1aeea12 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 = {}; }, @@ -79,6 +81,20 @@ module.exports = { return keplrNotificationWindow; }, + 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 waitAndClickByText(text, page = keplrWindow, exact = false) { await module.exports.waitForByText(text, page); const element = `:is(:text-is("${text}")${exact ? '' : `, :text("${text}")`})`; diff --git a/plugins/keplr-plugin.js b/plugins/keplr-plugin.js index 2d018276c..1b9430d4a 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, + disconnectWalletFromDapp: keplr.disconnectWalletFromDapp, setupWallet: async ({ secretWordsOrPrivateKey, password, diff --git a/support/commands.js b/support/commands.js index 0dac7f6a2..1e8053867 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'); +}); + +Cypress.Commands.add('switchToExtensionPermissionWindow', () => { + return cy.task('switchToExtensionPermissionWindow'); +}); + +Cypress.Commands.add('disconnectWalletFromDapp', () => { + return cy.task('disconnectWalletFromDapp'); }); \ 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 33cd1cd87..808231d37 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -29,6 +29,7 @@ describe('Keplr', () => { cy.visit('/'); cy.contains('Connect Wallet').click(); + cy.contains('Make an Offer').click(); cy.confirmTransaction().then(taskCompleted => { expect(taskCompleted).to.be.true; }); @@ -36,6 +37,14 @@ describe('Keplr', () => { }); }); + it(`should disconnect the wallet from all the connected DAPPs`, () => { + cy.switchToExtensionPermissionWindow().then(() => { + cy.disconnectWalletFromDapp().then(taskCompleted => { + expect(taskCompleted).to.be.true; + }); + }); + }); + it(`should complete Keplr setup by importing the wallet using private key`, () => { cy.switchToExtensionRegistrationWindow().then(() => { cy.setupWallet(