Skip to content

Commit

Permalink
fix(e2e): Fix typing issues and PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Vere-Grey committed Dec 6, 2024
1 parent 3a203e7 commit 4f37847
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 26 deletions.
13 changes: 9 additions & 4 deletions packages/suite-desktop-core/e2e/support/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type Fixtures = {

const test = base.extend<Fixtures>({
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);
Expand Down Expand Up @@ -81,7 +81,8 @@ const test = base.extend<Fixtures>({
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);
Expand All @@ -104,7 +105,11 @@ const test = base.extend<Fixtures>({
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);
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from '../../support/fixtures';

test.use({
emulatorStartConf: { wipe: true },
emulatorSetupConf: {
needs_backup: true,
mnemonic:
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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'] },
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions packages/suite-desktop-core/e2e/tests/spawn-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/src/support/useCypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion packages/suite/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion packages/trezor-user-env-link/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class TrezorUserEnvLinkClass extends TypedEmitter<WebsocketClientEvents>
private client: WebsocketClient;
public firmwares?: Firmwares;
private defaultFirmware?: string;
private defaultModel: Model = 'T2T1';
public defaultModel: Model = 'T2T1';

public currentEmulatorSetup?: Partial<SetupEmu> = {};
public currentEmulatorSettings: Partial<ApplySettings> = {};
Expand Down

0 comments on commit 4f37847

Please sign in to comment.