diff --git a/package.json b/package.json index 27a28fcd1..a1119007f 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "private": true, "scripts": { "build": "turbo build", - "build:cache": "turbo build:cache --filter=@synthetixio/synpress-metamask -- -m", - "build:cache:keplr": "turbo build:cache --filter=@synthetixio/synpress-keplr -- -k", + "build:cache": "turbo build:cache --filter=@synthetixio/synpress-metamask", + "build:cache:keplr": "turbo build:cache --filter=@synthetixio/synpress-keplr", "docs:build": "turbo docs:build --filter=docs", "format": "biome format . --write", "format:check": "biome format . --error-on-warnings", diff --git a/packages/cache/src/cli/cliEntrypoint.ts b/packages/cache/src/cli/cliEntrypoint.ts index 18f037547..6f117fe18 100644 --- a/packages/cache/src/cli/cliEntrypoint.ts +++ b/packages/cache/src/cli/cliEntrypoint.ts @@ -37,7 +37,7 @@ export const cliEntrypoint = async () => { .helpOption(undefined, 'Display help for command') .addHelpText('afterAll', `\n${footer}\n`) .parse(process.argv) - + console.log(WALLET_SETUP_DIR_NAME, program.args[0]) let walletSetupDir = program.args[0] if (!walletSetupDir) { walletSetupDir = path.join(process.cwd(), 'test', WALLET_SETUP_DIR_NAME) @@ -67,8 +67,8 @@ export const cliEntrypoint = async () => { } let extensionNames = extensionsToSetup() - if (!extensionNames) { - extensionNames = ['MetaMask'] + if (!extensionNames.length) { + extensionNames = ['Keplr'] } if (os.platform() === 'win32') { @@ -84,7 +84,7 @@ export const cliEntrypoint = async () => { } const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug) - + console.log('force', flags.force, 'compiledWalletSetupDirPath', compiledWalletSetupDirPath, 'extensionNames', extensionNames) for (const extensionName of extensionNames) { await createCache(compiledWalletSetupDirPath, () => prepareExtension(extensionName), flags.force); // Pass extensionName } diff --git a/wallets/keplr/src/KeplrWallet.ts b/wallets/keplr/src/KeplrWallet.ts index f2842e0a8..8d6b92e3c 100644 --- a/wallets/keplr/src/KeplrWallet.ts +++ b/wallets/keplr/src/KeplrWallet.ts @@ -1,5 +1,6 @@ import { type BrowserContext, type Page } from '@playwright/test' import { LockPage } from './pages/LockPage/page' +import { HomePage } from './pages/HomePage/page' export class KeplrWallet { seedPhrase = '' @@ -37,11 +38,20 @@ export class KeplrWallet { * @param password. The password to set. */ async setupWallet( - page: any, + page: Page, { secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string }, ) { const lockpage = new LockPage(page) const wallet = await lockpage.unlock(secretWordsOrPrivateKey, password) return wallet; } + + async getWalletAddress( + page: Page, + ) { + const homePage = new HomePage(page) + console.log('homePage', homePage, 1) + const walletAddress = await homePage.getWalletAddress() + return walletAddress; + } } diff --git a/wallets/keplr/src/cypress/setupTasks.ts b/wallets/keplr/src/cypress/setupTasks.ts index 4ebc8a689..bf8c549ea 100644 --- a/wallets/keplr/src/cypress/setupTasks.ts +++ b/wallets/keplr/src/cypress/setupTasks.ts @@ -1,13 +1,13 @@ -import { PASSWORD, SEED_PHRASE } from "../utils" -import { getKeplrWallet } from "./initKeplrWallet" +// import { PASSWORD, SEED_PHRASE } from "../utils" +// import { getKeplrWallet } from "./initKeplrWallet" export default function setupTasks(on: Cypress.PluginEvents) { on('task', { importWallet: async function () { - const keplrWallet = getKeplrWallet() - if (keplrWallet) { - await keplrWallet.setupWallet(null, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD }) - } + // const keplrWallet = getKeplrWallet() + // if (keplrWallet) { + // await keplrWallet.setupWallet(null, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD }) + // } return true } }) diff --git a/wallets/keplr/src/fixtures/keplrFixtures.ts b/wallets/keplr/src/fixtures/keplrFixtures.ts index 027f73e1c..67070361f 100644 --- a/wallets/keplr/src/fixtures/keplrFixtures.ts +++ b/wallets/keplr/src/fixtures/keplrFixtures.ts @@ -17,8 +17,8 @@ import { prepareExtension, getExtensionId } from '../fixtureActions' type KeplrFixtures = { _contextPath: string keplr: KeplrWallet - extensionId: string keplrPage: Page + extensionId: string } let _keplrPage: Page @@ -31,7 +31,8 @@ export const keplrFixtures = (walletSetup: ReturnType, await removeTempContextDir(contextDir) }, context: async ({ context: currentContext, _contextPath }, use) => { - const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash) + console.log('walletSetup', walletSetup, process.cwd(), CACHE_DIR_NAME) + const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash, 'context') if (!(await fs.exists(cacheDirPath))) { throw new Error(`Cache for ${walletSetup.hash} does not exist. Create it first!`) } @@ -79,15 +80,16 @@ export const keplrFixtures = (walletSetup: ReturnType, }, page: async ({ context }, use) => { const page = await context.newPage() - - await page.goto('/') + const extensionId = await getExtensionId(context, 'keplr') + await page.goto(`chrome-extension://${extensionId}/register.html`) await use(page) }, keplrPage: async ({ context: _ }, use) => { await use(_keplrPage) }, - keplr: async ({ context, extensionId }, use) => { + keplr: async ({ context }, use) => { + const extensionId = await getExtensionId(context, 'keplr') const keplrWallet = new KeplrWallet(_keplrPage, context, extensionId, PASSWORD) await keplrWallet.setupWallet(_keplrPage, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD }) await use(keplrWallet) diff --git a/wallets/keplr/src/pages/HomePage/actions/getWalletAddress.ts b/wallets/keplr/src/pages/HomePage/actions/getWalletAddress.ts index 93f1e8b81..98599871f 100644 --- a/wallets/keplr/src/pages/HomePage/actions/getWalletAddress.ts +++ b/wallets/keplr/src/pages/HomePage/actions/getWalletAddress.ts @@ -1,25 +1,16 @@ import type { Page } from '@playwright/test'; +import { homePageElements } from '../selectors'; export const getWalletAddress = async (page: Page) => { - console.log('getWalletAddress', page); - // return await playwright.waitAndGetValue(homePageElements.walletAddress); - // playwright.switchToKeplrWindow(); - // await module.exports.goToHome(); - // const newTokensSelctorExists = - // await playwright.waitForAndCheckElementExistence( - // homePageElements.newTokensFoundSelector, - // ); - - // if (newTokensSelctorExists) { - // await module.exports.addNewTokensFound(false); - // } - - // await playwright.waitAndClickByText(notificationPageElements.copyAddress); - // await playwright.waitAndClick( - // notificationPageElements.walletSelectors(chainName), - // ); - - // walletAddress = clipboardy.readSync(); - // await playwright.switchToCypressWindow(); - // return walletAddress; + await page.waitForLoadState('domcontentloaded'); + console.log(3) + const newTokensFoundSelector = await page.waitForSelector(homePageElements.newTokensFoundSelector); + console.log('New tokens found', newTokensFoundSelector); + if (newTokensFoundSelector) { + await page.waitForSelector(homePageElements.newTokensFoundSelector); + } + await page.waitForSelector(homePageElements.copyAddress); + const walletAddress = await page.click(homePageElements.copyAddress); + console.log('Wallet address copied', walletAddress); + return walletAddress; } \ No newline at end of file diff --git a/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/acceptAccess.ts b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/acceptAccess.ts new file mode 100644 index 000000000..d225ebf37 --- /dev/null +++ b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/acceptAccess.ts @@ -0,0 +1,13 @@ + +import { notificationPageElements } from '../selectors'; + +export const acceptAccess = async () => { + console.log('Accepting access in Keplr wallet', notificationPageElements); + // const notificationPage = await playwright.switchToKeplrNotification(); + // await playwright.waitAndClick( + // notificationPageElements.approveButton, + // notificationPage, + // { waitForEvent: 'close' }, + // ); + // return true; +} diff --git a/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/confirmAccess.ts b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/confirmAccess.ts new file mode 100644 index 000000000..9aa5b9586 --- /dev/null +++ b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/confirmAccess.ts @@ -0,0 +1,12 @@ +import { notificationPageElements } from "../selectors"; + +export const confirmTransaction = async () => { + console.log('Confirming transaction in Keplr wallet', notificationPageElements) + // const notificationPage = await playwright.switchToKeplrNotification(); + // await playwright.waitAndClick( + // notificationPageElements.approveButton, + // notificationPage, + // { waitForEvent: 'close' }, + // ); + return true; + } \ No newline at end of file diff --git a/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/index.ts b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/index.ts new file mode 100644 index 000000000..0c7179ffc --- /dev/null +++ b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/actions/index.ts @@ -0,0 +1,2 @@ +export * from './acceptAccess'; +export * from './confirmAccess'; \ No newline at end of file diff --git a/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/page.ts b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/page.ts new file mode 100644 index 000000000..1182e8090 --- /dev/null +++ b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/page.ts @@ -0,0 +1,22 @@ +import type { Page } from '@playwright/test' +import { notificationPageElements } from './selectors' +import { confirmTransaction, acceptAccess } from './actions' + +export class NotificationPage { + static readonly selectors = notificationPageElements + readonly selectors = notificationPageElements + + readonly page: Page + + constructor(page: Page) { + this.page = page + } + + async confirmTransaction() { + await confirmTransaction() + } + + async acceptAccess() { + await acceptAccess() + } +} diff --git a/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/selectors/index.ts b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/selectors/index.ts new file mode 100644 index 000000000..f247584b8 --- /dev/null +++ b/wallets/keplr/src/pages/HomePage/selectors/NotificationPage/selectors/index.ts @@ -0,0 +1,5 @@ +export const notificationPageElements = { + approveButton: 'button', + copyAddress: 'Copy Address', + walletSelectors: (chainName: string) => `img[alt="${chainName}"]`, +}; \ No newline at end of file diff --git a/wallets/keplr/src/pages/HomePage/selectors/index.ts b/wallets/keplr/src/pages/HomePage/selectors/index.ts index d4dbba6f5..73e1f7e38 100644 --- a/wallets/keplr/src/pages/HomePage/selectors/index.ts +++ b/wallets/keplr/src/pages/HomePage/selectors/index.ts @@ -5,4 +5,5 @@ export const homePageElements = { newTokensFound: 'new token(s) found', addChainsButton: 'Add Chains', newTokensFoundSelector: 'text=new token(s) found', + copyAddress: 'Copy Address', } \ No newline at end of file diff --git a/wallets/keplr/test/playwright/addAccount.spec.ts b/wallets/keplr/test/playwright/addAccount.spec.ts deleted file mode 100644 index aca838579..000000000 --- a/wallets/keplr/test/playwright/addAccount.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import test from '../synpress' -const { expect } = test - -test('add account', async ({ page, keplr }) => { - await page.click('text="Add Account"') - await page.click('text="Keplr"') - await page.click('text="Create Account"') -}) \ No newline at end of file diff --git a/wallets/keplr/test/playwright/getAddress.spec.ts b/wallets/keplr/test/playwright/getAddress.spec.ts new file mode 100644 index 000000000..013e3dd26 --- /dev/null +++ b/wallets/keplr/test/playwright/getAddress.spec.ts @@ -0,0 +1,7 @@ +import test from '../synpress' +const { expect } = test + +test.only('should get address', async ({ page, keplr }) => { + console.log('page', page, keplr) + expect(await keplr.getWalletAddress(page)).toBeTruthy() +}) \ No newline at end of file diff --git a/wallets/keplr/test/synpress.ts b/wallets/keplr/test/synpress.ts index 597385330..efe3086c3 100644 --- a/wallets/keplr/test/synpress.ts +++ b/wallets/keplr/test/synpress.ts @@ -2,4 +2,6 @@ import { testWithSynpress } from "@synthetixio/synpress-core"; import { keplrFixtures } from "../src"; import connectedSetup from "./wallet-setup/connected-keplr.setup"; +console.log('testWithSynpress', testWithSynpress, keplrFixtures, connectedSetup) + export default testWithSynpress(keplrFixtures(connectedSetup)) diff --git a/wallets/keplr/test/wallet-setup/connected-wallet.setup.d.ts b/wallets/keplr/test/wallet-setup/connected-wallet.setup.d.ts new file mode 100644 index 000000000..1bc70ea7c --- /dev/null +++ b/wallets/keplr/test/wallet-setup/connected-wallet.setup.d.ts @@ -0,0 +1,9 @@ +export declare const SEED_PHRASE = 'test test test test test test test test test test test junk' +export declare const PASSWORD = 'Tester@1234' +declare const _default: { + hash: string + fn: import('@synthetixio/synpress-cache').WalletSetupFunction + walletPassword: string +} +export default _default +//# sourceMappingURL=basic.setup.d.ts.map