From c4bf8588664b957e973cc95e45b6f52ee3855565 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 6 Mar 2024 14:17:47 +0500 Subject: [PATCH] feature: adding behavior in import wallet flow to select a chain when importing/creating wallet --- commands/keplr.js | 20 ++++++++++++++++---- commands/playwright-keplr.js | 1 + pages/keplr/first-time-flow-page.js | 6 ++++++ tests/e2e/specs/keplr/keplr-spec.js | 22 +++++++++++----------- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/commands/keplr.js b/commands/keplr.js index 7463c199e..5f29990b6 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -158,10 +158,7 @@ const keplr = { await playwright.keplrWindow(), ); - await playwright.waitAndClick( - onboardingElements.submitChainButton, - await playwright.keplrWindow(), - ); + await module.exports.handleSelectChain(); await playwright.waitForByText( onboardingElements.phraseAccountCreated, @@ -170,6 +167,21 @@ const keplr = { return true; }, + async handleSelectChain() { + const chainNameExists = await playwright.waitForAndCheckElementExistence(onboardingElements.chainNameSelector); + + if (chainNameExists) { + await playwright.waitAndClickByText(onboardingElements.chainName, playwright.keplrWindow()); + await playwright.waitAndClick(onboardingElements.submitChainButton, playwright.keplrWindow()); + const importButtonExists = await playwright.waitForAndCheckElementExistence(onboardingElements.importButtonSelector); + + if (importButtonExists) { + await playwright.waitAndClick(onboardingElements.importButtonSelector, playwright.keplrWindow()); + } + } else { + await playwright.waitAndClick(onboardingElements.submitChainButton, playwright.keplrWindow()); + } + }, async importWalletWithPhrase(secretWords) { await playwright.waitAndClickByText( onboardingElements.phraseCount24, diff --git a/commands/playwright-keplr.js b/commands/playwright-keplr.js index ba2ec17eb..04725a425 100644 --- a/commands/playwright-keplr.js +++ b/commands/playwright-keplr.js @@ -271,6 +271,7 @@ module.exports = { page = keplrWindow, ) { try { + await module.exports.waitUntilStable(page); await page.waitForSelector(selector, { timeout }); return true; } catch (error) { diff --git a/pages/keplr/first-time-flow-page.js b/pages/keplr/first-time-flow-page.js index 3d6e6337b..4b81860a0 100644 --- a/pages/keplr/first-time-flow-page.js +++ b/pages/keplr/first-time-flow-page.js @@ -14,12 +14,17 @@ const phraseAccountCreated = 'Account Created!'; const finishButton = 'button[type="button"]'; const textAreaSelector = 'textbox'; const submitPhraseButton = 'button[type="submit"]'; +const chainName = 'Agoric local' +const chainNameSelector = 'text=Agoric local' +const importButtonSelector = 'button:has-text("Import")' module.exports.onboardingElements = { existingWalletButton, createWalletButton, importRecoveryPhraseButton, useRecoveryPhraseButton, + chainNameSelector, + importButtonSelector, phraseCount24, phrasePrivateKey, walletInput, @@ -32,4 +37,5 @@ module.exports.onboardingElements = { finishButton, textAreaSelector, submitPhraseButton, + chainName }; diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index 527382a82..0592b1096 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -2,18 +2,13 @@ describe('Keplr', () => { context('Test commands', () => { - it(`should create a new wallet using 24 word phrase`, () => { - 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, - 'My Wallet 2', - ).then(setupFinished => { + it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => { + cy.setupWallet().then(setupFinished => { expect(setupFinished).to.be.true; }); + cy.visit('/'); }); it(`should reject connection with wallet`, () => { - cy.visit('/'); const alertShown = cy.stub().as('alertShown'); cy.on('window:alert', alertShown); @@ -60,8 +55,13 @@ describe('Keplr', () => { 'Offer accepted', ); }); - it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => { - cy.setupWallet().then(setupFinished => { + it(`should create a new wallet using 24 word phrase`, () => { + 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, + 'My Wallet 2', + ).then(setupFinished => { expect(setupFinished).to.be.true; }); }); @@ -105,4 +105,4 @@ describe('Keplr', () => { }); }); }); -}); +}); \ No newline at end of file