From aee18bf62bfc3e68b1df83000fcf2ca6152ded8e Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 6 Mar 2024 20:34:48 +0500 Subject: [PATCH] chore: updating selector for getting wallet address and adding test cases to validate the behavior --- commands/keplr.js | 8 ++++---- pages/keplr/notification-page.js | 12 +++++++++--- support/commands.js | 5 +++-- tests/e2e/specs/keplr/keplr-spec.js | 18 ++++++++++++++++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/commands/keplr.js b/commands/keplr.js index ab40e2bc5..bef834921 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -267,10 +267,10 @@ const keplr = { return true; }, - async getWalletAddress() { + async getWalletAddress(chainName) { playwright.switchToKeplrWindow(); await module.exports.goToHome(); - const newTokensSelctorExists = playwright.waitForAndCheckElementExistence( + const newTokensSelctorExists = await playwright.waitForAndCheckElementExistence( homePageElements.newTokensFoundSelector, ); @@ -278,9 +278,9 @@ const keplr = { await module.exports.addNewTokensFound(false); } - const page = playwright.keplrWindow(); await playwright.waitAndClickByText(notificationPageElements.copyAddress); - await page.click(notificationPageElements.copyWalletAddressSelector); + await playwright.waitAndClick(notificationPageElements.walletSelectors[chainName]) + walletAddress = clipboardy.readSync(); await playwright.switchToCypressWindow(); return walletAddress; diff --git a/pages/keplr/notification-page.js b/pages/keplr/notification-page.js index e04726c24..81ac42cc1 100644 --- a/pages/keplr/notification-page.js +++ b/pages/keplr/notification-page.js @@ -1,9 +1,15 @@ const approveButton = `button`; const copyAddress = 'Copy Address'; -const copyWalletAddressSelector = 'div.sc-dkzDqf div.sc-hKMtZM.sc-kDDrLX.cyoEAq.dkJSBQ' +const copyWalletAddressSelector = + 'div.sc-dkzDqf div.sc-hKMtZM.sc-kDDrLX.cyoEAq.dkJSBQ'; +const walletSelectors = { + AGORIC: 'img[alt="Agoric local"]', + COSMOS: 'img[alt="Cosmos Hub"]', +}; module.exports.notificationPageElements = { approveButton, copyAddress, - copyWalletAddressSelector -}; \ No newline at end of file + copyWalletAddressSelector, + walletSelectors +}; diff --git a/support/commands.js b/support/commands.js index a0ca6ecdc..d8399b5b4 100644 --- a/support/commands.js +++ b/support/commands.js @@ -455,11 +455,12 @@ Cypress.Commands.add('disconnectWalletFromDapp', () => { return cy.task('disconnectWalletFromDapp'); }); -Cypress.Commands.add('getWalletAddress', () => { - cy.task('getWalletAddress').then(address => { +Cypress.Commands.add('getWalletAddress', chainName => { + cy.task('getWalletAddress', chainName).then(address => { return address; }); }); + Cypress.Commands.add('switchWallet', walletName => { return cy.task('switchWallet', { walletName }); }); diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index 9eed9e107..0c38d4474 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -75,6 +75,16 @@ describe('Keplr', () => { expect(setupFinished).to.be.true; }); }); + + it(`should get wallet address while running addNewTokensFound flow`, () => { + cy.getWalletAddress('AGORIC').then(walletAddress => { + expect(walletAddress.length).to.be.equal(45); + }); + + cy.getWalletAddress('COSMOS').then(walletAddress => { + expect(walletAddress.length).to.be.equal(45); + }); + }); it(`should switch to new wallet by name`, () => { cy.switchWallet('My Wallet 2').then(taskCompleted => { expect(taskCompleted).to.be.true; @@ -102,8 +112,12 @@ describe('Keplr', () => { }); }); - it(`should get wallet address`, () => { - cy.getWalletAddress().then(walletAddress => { + it(`should get wallet address without running addNewTokensFound flow`, () => { + cy.getWalletAddress('AGORIC').then(walletAddress => { + expect(walletAddress.length).to.be.equal(45); + }); + + cy.getWalletAddress('COSMOS').then(walletAddress => { expect(walletAddress.length).to.be.equal(45); }); });