Skip to content

Commit

Permalink
chore: updating selector for getting wallet address and adding test c…
Browse files Browse the repository at this point in the history
…ases to validate the behavior
  • Loading branch information
rabi-siddique committed Mar 6, 2024
1 parent a5713d7 commit aee18bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
8 changes: 4 additions & 4 deletions commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,20 @@ 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,
);

if (newTokensSelctorExists) {
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;
Expand Down
12 changes: 9 additions & 3 deletions pages/keplr/notification-page.js
Original file line number Diff line number Diff line change
@@ -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
};
copyWalletAddressSelector,
walletSelectors
};
5 changes: 3 additions & 2 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down
18 changes: 16 additions & 2 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
Expand Down

0 comments on commit aee18bf

Please sign in to comment.