Skip to content

Commit

Permalink
Merge pull request #1 from rabi-siddique/rs-integrating-keplr-with-sy…
Browse files Browse the repository at this point in the history
…npress

Initial setup to integrate Keplr with Synpress
  • Loading branch information
rabi-siddique authored Feb 28, 2024
2 parents 9466f3e + 61f7a96 commit 3cc4781
Show file tree
Hide file tree
Showing 19 changed files with 1,033 additions and 214 deletions.
146 changes: 146 additions & 0 deletions commands/keplr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
const log = require('debug')('synpress:keplr');
const playwright = require('./playwright-keplr');
const { onboardingElements } = require('../pages/keplr/first-time-flow-page');
const {
notificationPageElements,
} = require('../pages/keplr/notification-page');

let extensionId;
let extensionVersion;

const keplr = {
async resetState() {
log('Resetting state of keplr');
extensionId = undefined;
extensionVersion = undefined;
},
extensionId: () => {
return extensionId;
},
extensionUrls: () => {
return {
extensionImportAccountUrl,
};
},

async getExtensionDetails() {
const keplrExtensionData = (await playwright.getExtensionsData()).keplr;

extensionId = keplrExtensionData.id;
extensionVersion = keplrExtensionData.version;

return {
extensionId,
extensionVersion,
};
},

async importWallet(secretWords, password) {
await playwright.waitAndClickByText(
onboardingElements.createWalletButton,
await playwright.keplrWindow(),
);
await playwright.waitAndClickByText(
onboardingElements.importRecoveryPhraseButton,
await playwright.keplrWindow(),
);
await playwright.waitAndClickByText(
onboardingElements.useRecoveryPhraseButton,
await playwright.keplrWindow(),
);
await playwright.waitAndClickByText(
onboardingElements.phraseCount24,
await playwright.keplrWindow(),
);

for (const [index, word] of secretWords.split(' ').entries()) {
await playwright.waitAndTypeByLocator(
onboardingElements.textAreaSelector,
word,
index,
);
}

await playwright.waitAndClick(
onboardingElements.submitPhraseButton,
await playwright.keplrWindow(),
);

await playwright.waitAndType(
onboardingElements.walletInput,
onboardingElements.walletName,
);
await playwright.waitAndType(onboardingElements.passwordInput, password);
await playwright.waitAndType(
onboardingElements.confirmPasswordInput,
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 acceptAccess() {
const notificationPage = await playwright.switchToKeplrNotification();
await playwright.waitAndClick(
notificationPageElements.approveButton,
notificationPage,
{ waitForEvent: 'close' },
);
return true;
},

async confirmTransaction() {
const notificationPage = await playwright.switchToKeplrNotification();
await playwright.waitAndClick(
notificationPageElements.approveButton,
notificationPage,
{ waitForEvent: 'close' },
);
return true;
},

async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, password },
) {
if (playwrightInstance) {
await playwright.init(playwrightInstance);
} else {
await playwright.init();
}

await playwright.assignWindows();
await playwright.assignActiveTabName('keplr');
await module.exports.getExtensionDetails();
await module.exports.importWallet(secretWordsOrPrivateKey, password);
},
};

module.exports = keplr;
2 changes: 1 addition & 1 deletion commands/metamask.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const log = require('debug')('synpress:metamask');
const playwright = require('./playwright');
const playwright = require('./playwright-metamask');
const sleep = require('util').promisify(setTimeout);

const {
Expand Down
Loading

0 comments on commit 3cc4781

Please sign in to comment.