diff --git a/wallets/phantom/src/cypress/Phantom.ts b/wallets/phantom/src/cypress/Phantom.ts index 22e7c081..bfcd2548 100644 --- a/wallets/phantom/src/cypress/Phantom.ts +++ b/wallets/phantom/src/cypress/Phantom.ts @@ -33,7 +33,7 @@ export default class Phantom { */ async getAccount(): Promise { return await this.phantomExtensionPage - .locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountButton) + .locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountName) .innerText() } @@ -45,14 +45,6 @@ export default class Phantom { return await this.phantomPlaywright.getAccountAddress(network) } - /** - * Gets the current network name. - * @returns The current network name - */ - async getNetwork(): Promise { - return await this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.currentNetwork).innerText() - } - /** * Connects Phantom to a dApp. * @param accounts - Optional array of account addresses to connect @@ -91,7 +83,7 @@ export default class Phantom { async addNewAccount(accountName: string): Promise { await this.phantomPlaywright.addNewAccount(accountName) await expect( - this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountButton) + this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountName) ).toHaveText(accountName) return true } @@ -104,7 +96,7 @@ export default class Phantom { async switchAccount(accountName: string): Promise { await this.phantomPlaywright.switchAccount(accountName) await expect( - this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountButton) + this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountName) ).toHaveText(accountName) return true } @@ -124,10 +116,6 @@ export default class Phantom { newAccountName: string }): Promise { await this.phantomPlaywright.renameAccount(currentAccountName, newAccountName) - await this.phantomExtensionPage.locator(HomePageSelectors.threeDotsMenu.accountDetailsCloseButton).click() - await expect( - this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountButton) - ).toHaveText(newAccountName) return true } @@ -253,6 +241,15 @@ export default class Phantom { return true } + /** + * Navigates back to the home page. + * @returns True if the navigation was successful + */ + async goToHomePage(): Promise { + await this.phantomPlaywright.goToHomePage() + return true + } + /** * Navigates back to the home page. * @returns True if the navigation was successful diff --git a/wallets/phantom/src/cypress/configureSynpress.ts b/wallets/phantom/src/cypress/configureSynpress.ts index 670ed357..86c883c7 100644 --- a/wallets/phantom/src/cypress/configureSynpress.ts +++ b/wallets/phantom/src/cypress/configureSynpress.ts @@ -125,9 +125,6 @@ export default function configureSynpress( }) => phantom?.renameAccount({ currentAccountName, newAccountName }), resetApp: () => phantom?.resetApp(), - // Network - getNetwork: () => phantom?.getNetwork(), - // Token approveTokenPermission: (options?: { spendLimit?: number | 'max' @@ -149,6 +146,7 @@ export default function configureSynpress( toggleTestnetMode: () => phantom?.toggleTestnetMode(), // Others + goToHomePage: () => phantom?.goToHomePage(), goBackToHomePage: () => phantom?.goBackToHomePage(), openSettings: () => phantom?.openSettings() }) diff --git a/wallets/phantom/src/cypress/support/importPhantomWallet.ts b/wallets/phantom/src/cypress/support/importPhantomWallet.ts index 06fa30b0..b98042f8 100644 --- a/wallets/phantom/src/cypress/support/importPhantomWallet.ts +++ b/wallets/phantom/src/cypress/support/importPhantomWallet.ts @@ -30,6 +30,8 @@ export default async function importPhantomWallet(port: number, importDefaultWal if (importDefaultWallet) await phantom.importWallet(SEED_PHRASE) + await phantom.goToHomePage() + cypressPage = context.pages()[extensionPageIndex === 1 ? 0 : 1] as Page await cypressPage.bringToFront() } diff --git a/wallets/phantom/src/cypress/support/synpressCommands.ts b/wallets/phantom/src/cypress/support/synpressCommands.ts index aaf78e18..dbd191a9 100644 --- a/wallets/phantom/src/cypress/support/synpressCommands.ts +++ b/wallets/phantom/src/cypress/support/synpressCommands.ts @@ -18,7 +18,6 @@ declare global { importWalletFromPrivateKey(privateKey: string): Chainable getAccount(): Chainable - getNetwork(): Chainable connectToDapp(accounts?: string[]): Chainable @@ -46,6 +45,7 @@ declare global { toggleTestnetMode(): Chainable + goToHomePage(): Chainable goBackToHomePage(): Chainable openSettings(): Chainable } @@ -151,15 +151,6 @@ export default function synpressCommandsForPhantom(): void { return cy.task('resetApp') }) - // Network - - /** - * Gets the current network - */ - Cypress.Commands.add('getNetwork', () => { - return cy.task('getNetwork') - }) - // Token /** @@ -239,6 +230,13 @@ export default function synpressCommandsForPhantom(): void { return cy.task('rejectTransaction') }) + /** + * Navigates to the Phantom extension home page + */ + Cypress.Commands.add('goToHomePage', () => { + return cy.task('goToHomePage') + }) + /** * Goes back to the home page */ diff --git a/wallets/phantom/src/playwright/Phantom.ts b/wallets/phantom/src/playwright/Phantom.ts index 6384ec59..9352e0d8 100644 --- a/wallets/phantom/src/playwright/Phantom.ts +++ b/wallets/phantom/src/playwright/Phantom.ts @@ -267,6 +267,17 @@ export class Phantom extends PhantomAbstract { await this.notificationPage.rejectTokenPermission(this.extensionId) } + /** + * Navigates to the home page or wallet dashboard. + */ + async goToHomePage(): Promise { + if (!this.extensionId) { + throw NO_EXTENSION_ID_ERROR + } + + await this.homePage.goToHomePage(this.extensionId) + } + /** * Navigates back to the home page. */ diff --git a/wallets/phantom/src/playwright/pages/HomePage/page.ts b/wallets/phantom/src/playwright/pages/HomePage/page.ts index d3a586f1..7fc9b3ff 100644 --- a/wallets/phantom/src/playwright/pages/HomePage/page.ts +++ b/wallets/phantom/src/playwright/pages/HomePage/page.ts @@ -22,6 +22,10 @@ export class HomePage { this.page = page } + async goToHomePage(extensionId: string) { + await this.page.goto(`chrome-extension://${extensionId}/popup.html`) + } + async goBackToHomePage() { await this.page.locator(Selectors.settings.closeSettingsButton).click() } diff --git a/wallets/phantom/src/playwright/pages/OnboardingPage/actions/importWallet.ts b/wallets/phantom/src/playwright/pages/OnboardingPage/actions/importWallet.ts index 590dbc27..2af16c1f 100644 --- a/wallets/phantom/src/playwright/pages/OnboardingPage/actions/importWallet.ts +++ b/wallets/phantom/src/playwright/pages/OnboardingPage/actions/importWallet.ts @@ -17,7 +17,7 @@ export async function importWallet(page: Page, seedPhrase: string, password: str await expect( page.locator(Selectors.SecretRecoveryPhrasePageSelectors.viewAccountsButton), 'Import accounts success screen should be visible' - ).toBeVisible({ timeout: 10_000 }) + ).toBeVisible({ timeout: 30_000 }) await page.locator(Selectors.SecretRecoveryPhrasePageSelectors.continueButton).click() diff --git a/wallets/phantom/src/type/PhantomAbstract.ts b/wallets/phantom/src/type/PhantomAbstract.ts index 565d27d4..21f388c7 100644 --- a/wallets/phantom/src/type/PhantomAbstract.ts +++ b/wallets/phantom/src/type/PhantomAbstract.ts @@ -123,6 +123,11 @@ export abstract class PhantomAbstract { */ abstract rejectTokenPermission(): void + /** + * Navigates to the home page of Phantom tab. + */ + abstract goToHomePage(): void + /** * Goes back to the home page of Phantom tab. */ diff --git a/wallets/phantom/test/cypress/addNewAccount.cy.ts b/wallets/phantom/test/cypress/addNewAccount.cy.ts index f9cc5df9..f5bc382c 100644 --- a/wallets/phantom/test/cypress/addNewAccount.cy.ts +++ b/wallets/phantom/test/cypress/addNewAccount.cy.ts @@ -1,4 +1,4 @@ -it.only('should add a new account with a specified name', () => { +it('should add a new account with a specified name', () => { const accountName = 'Test Account 2' cy.addNewAccount(accountName).then(() => { diff --git a/wallets/phantom/test/cypress/renameAccount.cy.ts b/wallets/phantom/test/cypress/renameAccount.cy.ts new file mode 100644 index 00000000..fc17f21b --- /dev/null +++ b/wallets/phantom/test/cypress/renameAccount.cy.ts @@ -0,0 +1,10 @@ +const newAccountName = 'New Name' + +it('should rename currently connected account with specified name', () => { + cy.addNewAccount(newAccountName).then(() => { + cy.renameAccount(newAccountName, 'Renaming test').then(() => { + cy.goToHomePage() + cy.getAccount().should('eq', 'Renaming test') + }) + }) +}) diff --git a/wallets/phantom/test/cypress/switchAccount.cy.ts b/wallets/phantom/test/cypress/switchAccount.cy.ts new file mode 100644 index 00000000..c582fee4 --- /dev/null +++ b/wallets/phantom/test/cypress/switchAccount.cy.ts @@ -0,0 +1,13 @@ +import { defaultAccount } from '../../src/cypress/constans' + +it('should switch back to the `Account 1` account', () => { + const accountName = 'New Name' + + cy.addNewAccount(accountName).then(() => { + cy.getAccount().should('eq', accountName) + }) + + cy.switchAccount(defaultAccount).then(() => { + cy.getAccount().should('eq', defaultAccount) + }) +})