diff --git a/packages/suite-desktop-core/e2e/support/fixtures.ts b/packages/suite-desktop-core/e2e/support/fixtures.ts index c71bd55117b..4500e15088c 100644 --- a/packages/suite-desktop-core/e2e/support/fixtures.ts +++ b/packages/suite-desktop-core/e2e/support/fixtures.ts @@ -33,8 +33,8 @@ type Fixtures = { const test = base.extend({ startEmulator: true, - emulatorStartConf: { wipe: true }, - emulatorSetupConf: { needs_backup: true, mnemonic: 'mnemonic_all' }, + emulatorStartConf: {}, + emulatorSetupConf: {}, /* eslint-disable-next-line no-empty-pattern */ trezorUserEnvLink: async ({}, use) => { await use(TrezorUserEnvLink); @@ -81,7 +81,8 @@ const test = base.extend({ await window.context().tracing.stop({ path: tracePath }); } else { await page.context().addInitScript(() => { - window.Cypress = true; + // Tells the app to attach Redux Store to window object. packages/suite-web/src/support/useCypress.ts + window.Playwright = true; }); await page.goto('./'); await use(page); @@ -104,7 +105,11 @@ const test = base.extend({ await use(walletPage); }, onboardingPage: async ({ window, emulatorStartConf }, use, testInfo) => { - const onboardingPage = new OnboardingActions(window, emulatorStartConf.model, testInfo); + const onboardingPage = new OnboardingActions( + window, + emulatorStartConf.model ?? TrezorUserEnvLink.defaultModel, + testInfo, + ); await use(onboardingPage); }, }); diff --git a/packages/suite-desktop-core/e2e/support/pageActions/onboardingActions.ts b/packages/suite-desktop-core/e2e/support/pageActions/onboardingActions.ts index f059eff2838..0f62041d41b 100644 --- a/packages/suite-desktop-core/e2e/support/pageActions/onboardingActions.ts +++ b/packages/suite-desktop-core/e2e/support/pageActions/onboardingActions.ts @@ -1,12 +1,12 @@ import { Locator, Page, TestInfo, expect } from '@playwright/test'; import { Model, TrezorUserEnvLink } from '@trezor/trezor-user-env-link'; -import { SUITE as SuiteActions } from '@trezor/suite/src/actions/suite/constants'; +import * as SuiteActions from '@trezor/suite/src/actions/suite/constants/suiteConstants'; import { PlaywrightProjects } from '../../playwright.config'; export class OnboardingActions { - readonly model: Model | undefined; + readonly model: Model; readonly testInfo: TestInfo; readonly welcomeTitle: Locator; readonly analyticsHeading: Locator; @@ -17,10 +17,11 @@ export class OnboardingActions { readonly connectDevicePrompt: Locator; readonly authenticityStartButton: Locator; readonly authenticityContinueButton: Locator; + isModelWithSecureElement = () => ['T2B1', 'T3T1'].includes(this.model); constructor( public window: Page, - model: Model | undefined, + model: Model, testInfo: TestInfo, ) { this.model = model; @@ -47,10 +48,13 @@ export class OnboardingActions { } async completeOnboarding() { + if (this.testInfo.project.name === PlaywrightProjects.Web) { + await this.disableFirmwareHashCheck(); + } await this.optionallyDismissFwHashCheckError(); await this.analyticsContinueButton.click(); await this.onboardingContinueButton.click(); - if (this.model && ['T2B1', 'T3T1'].includes(this.model)) { + if (this.isModelWithSecureElement()) { await this.authenticityStartButton.click(); await TrezorUserEnvLink.pressYes(); await this.authenticityContinueButton.click(); @@ -60,11 +64,7 @@ export class OnboardingActions { } async disableFirmwareHashCheck() { - if (this.testInfo.project.name === PlaywrightProjects.Desktop) { - // Desktop app starts already with disabled hash check - return; - } - + // Desktop starts with already disabled firmware hash check. Web needs to disable it. await expect(this.welcomeTitle).toBeVisible({ timeout: 10000 }); // eslint-disable-next-line @typescript-eslint/no-shadow await this.window.evaluate(SuiteActions => { diff --git a/packages/suite-desktop-core/e2e/support/pageActions/settingsActions.ts b/packages/suite-desktop-core/e2e/support/pageActions/settingsActions.ts index 569005a7d20..ccf20402d98 100644 --- a/packages/suite-desktop-core/e2e/support/pageActions/settingsActions.ts +++ b/packages/suite-desktop-core/e2e/support/pageActions/settingsActions.ts @@ -4,7 +4,7 @@ import { BackendType, NetworkSymbol } from '@suite-common/wallet-config'; export class SettingsActions { private readonly window: Page; - private readonly TIMES_CLICK_TO_SET_DEBUG_MODE = 7; + private readonly TIMES_CLICK_TO_SET_DEBUG_MODE = 5; readonly settingsMenuButton: Locator; readonly settingsHeader: Locator; readonly debugTabButton: Locator; @@ -61,10 +61,6 @@ export class SettingsActions { async toggleDebugModeInSettings() { await expect(this.settingsHeader).toBeVisible(); - const isDebugModeAlreadyToggled = await this.debugTabButton.isVisible(); - if (isDebugModeAlreadyToggled) { - return; - } for (let i = 0; i < this.TIMES_CLICK_TO_SET_DEBUG_MODE; i++) { await this.settingsHeader.click(); } diff --git a/packages/suite-desktop-core/e2e/tests/general/cardano-discovery.test.ts b/packages/suite-desktop-core/e2e/tests/general/cardano-discovery.test.ts index 0467b14d9a9..d5d484e5f90 100644 --- a/packages/suite-desktop-core/e2e/tests/general/cardano-discovery.test.ts +++ b/packages/suite-desktop-core/e2e/tests/general/cardano-discovery.test.ts @@ -1,6 +1,7 @@ import { test, expect } from '../../support/fixtures'; test.use({ + emulatorStartConf: { wipe: true }, emulatorSetupConf: { needs_backup: true, mnemonic: diff --git a/packages/suite-desktop-core/e2e/tests/general/wallet-discovery.test.ts b/packages/suite-desktop-core/e2e/tests/general/wallet-discovery.test.ts index e382f702647..3735d5be912 100644 --- a/packages/suite-desktop-core/e2e/tests/general/wallet-discovery.test.ts +++ b/packages/suite-desktop-core/e2e/tests/general/wallet-discovery.test.ts @@ -1,5 +1,10 @@ import { test, expect } from '../../support/fixtures'; +test.use({ + emulatorStartConf: { wipe: true }, + emulatorSetupConf: { needs_backup: true, mnemonic: 'mnemonic_all' }, +}); + test.beforeEach(async ({ onboardingPage, dashboardPage }) => { await onboardingPage.completeOnboarding(); await dashboardPage.discoveryShouldFinish(); diff --git a/packages/suite-desktop-core/e2e/tests/settings/electrum.test.ts b/packages/suite-desktop-core/e2e/tests/settings/electrum.test.ts index 4a030217579..72845f04e9b 100644 --- a/packages/suite-desktop-core/e2e/tests/settings/electrum.test.ts +++ b/packages/suite-desktop-core/e2e/tests/settings/electrum.test.ts @@ -1,5 +1,10 @@ import { test, expect } from '../../support/fixtures'; +test.use({ + emulatorStartConf: { wipe: true }, + emulatorSetupConf: { needs_backup: true, mnemonic: 'mnemonic_all' }, +}); + test.describe.serial( 'Suite works with Electrum server', { tag: ['@group=settings', '@desktopOnly'] }, @@ -21,7 +26,6 @@ test.describe.serial( const electrumUrl = '127.0.0.1:50001:t'; await settingsPage.navigateTo(); - await settingsPage.toggleDebugModeInSettings(); await settingsPage.coinsTabButton.click(); await settingsPage.openCoinAdvanceSettings('regtest'); await settingsPage.changeCoinBackend('electrum', electrumUrl); diff --git a/packages/suite-desktop-core/e2e/tests/settings/t2b1-device-settings.test.ts b/packages/suite-desktop-core/e2e/tests/settings/t2b1-device-settings.test.ts index 7e485ce26bb..8e54cd93b11 100644 --- a/packages/suite-desktop-core/e2e/tests/settings/t2b1-device-settings.test.ts +++ b/packages/suite-desktop-core/e2e/tests/settings/t2b1-device-settings.test.ts @@ -8,11 +8,9 @@ import { test, expect } from '../../support/fixtures'; test.describe.serial('T2B1 - Device settings', { tag: ['@group=settings'] }, () => { test.use({ emulatorStartConf: { version: '2-latest', model: 'T2B1', wipe: true }, - emulatorSetupConf: {}, }); test.beforeEach(async ({ onboardingPage, settingsPage }) => { - await onboardingPage.disableFirmwareHashCheck(); await onboardingPage.completeOnboarding(); await settingsPage.navigateTo(); await settingsPage.deviceTabButton.click(); diff --git a/packages/suite-desktop-core/e2e/tests/spawn-bridge.test.ts b/packages/suite-desktop-core/e2e/tests/spawn-bridge.test.ts index 81f4ed07858..116dc8c9ee4 100644 --- a/packages/suite-desktop-core/e2e/tests/spawn-bridge.test.ts +++ b/packages/suite-desktop-core/e2e/tests/spawn-bridge.test.ts @@ -44,14 +44,18 @@ test.describe.serial('Bridge', { tag: ['@group=suite', '@desktopOnly'] }, () => test('App acquired device, EXTERNAL bridge is restarted, app reconnects', async ({ trezorUserEnvLink, - }) => { + }, testInfo) => { await trezorUserEnvLink.startEmu({ wipe: true, version: '2-latest', model: 'T2T1' }); await trezorUserEnvLink.setupEmu({}); await trezorUserEnvLink.startBridge(LEGACY_BRIDGE_VERSION); const suite = await launchSuite(); await suite.window.title(); - const onboardingPage = new OnboardingActions(suite.window); + const onboardingPage = new OnboardingActions( + suite.window, + trezorUserEnvLink.defaultModel, + testInfo, + ); await onboardingPage.completeOnboarding(); await trezorUserEnvLink.stopBridge(); diff --git a/packages/suite-desktop-core/tsconfig.json b/packages/suite-desktop-core/tsconfig.json index 2c09ec5b0b6..16e9242c560 100644 --- a/packages/suite-desktop-core/tsconfig.json +++ b/packages/suite-desktop-core/tsconfig.json @@ -32,6 +32,7 @@ { "path": "../node-utils" }, { "path": "../request-manager" }, { "path": "../suite-desktop-api" }, + { "path": "../suite" }, { "path": "../transport-bridge" }, { "path": "../urls" }, { "path": "../utils" }, diff --git a/packages/suite-web/src/support/useCypress.ts b/packages/suite-web/src/support/useCypress.ts index f350a472f15..151374888b4 100644 --- a/packages/suite-web/src/support/useCypress.ts +++ b/packages/suite-web/src/support/useCypress.ts @@ -11,7 +11,7 @@ export const useCypress = () => { const store = useStore(); useEffect(() => { - if (typeof window !== 'undefined' && window.Cypress) { + if (typeof window !== 'undefined' && (window.Cypress || window.Playwright)) { window.store = store; window.TrezorConnect = TrezorConnect; diff --git a/packages/suite/global.d.ts b/packages/suite/global.d.ts index 7f8d1c3c276..fc8993a795d 100644 --- a/packages/suite/global.d.ts +++ b/packages/suite/global.d.ts @@ -2,8 +2,9 @@ interface Window { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose; chrome?: any; // Only in Chromium browsers - // Needed for Cypress + // Needed for Cypress and Playwright Cypress?: any; + Playwright?: any; TrezorConnect?: any; store?: any; } diff --git a/packages/trezor-user-env-link/src/api.ts b/packages/trezor-user-env-link/src/api.ts index 4af222590de..7363c8b3a41 100644 --- a/packages/trezor-user-env-link/src/api.ts +++ b/packages/trezor-user-env-link/src/api.ts @@ -70,7 +70,7 @@ export class TrezorUserEnvLinkClass extends TypedEmitter private client: WebsocketClient; public firmwares?: Firmwares; private defaultFirmware?: string; - private defaultModel: Model = 'T2T1'; + public defaultModel: Model = 'T2T1'; public currentEmulatorSetup?: Partial = {}; public currentEmulatorSettings: Partial = {};