Skip to content

Commit

Permalink
refactoring(e2e): Use viewport arg for electron and allow snapshots v…
Browse files Browse the repository at this point in the history
…alidations

minor refactoring of elecotron launch methods
  • Loading branch information
Vere-Grey committed Jan 15, 2025
1 parent a5c9310 commit 8d0cee1
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 36 deletions.
2 changes: 0 additions & 2 deletions packages/suite-desktop-core/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const config: PlaywrightTestConfig = {
name: PlaywrightProjects.Desktop,
use: {},
grepInvert: /@webOnly/,
//TODO: #16073 We cannot set resolution for Electron. Once solved, remove ignoreSnapshots
ignoreSnapshots: true,
},
],
testDir: 'tests',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions packages/suite-desktop-core/e2e/support/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type LaunchSuiteParams = {
bridgeDaemon?: boolean;
locale?: string;
colorScheme?: 'light' | 'dark' | 'no-preference' | null | undefined;
videoFolder?: string;
videoFolder: string;
viewport: { width: number; height: number };
};

const formatErrorLogMessage = (data: string) => {
Expand All @@ -29,7 +30,7 @@ const formatErrorLogMessage = (data: string) => {
return `${red}${data}${reset}`;
};

export const launchSuiteElectronApp = async (params: LaunchSuiteParams = {}) => {
export const launchSuiteElectronApp = async (params: LaunchSuiteParams) => {
const defaultParams = {
rmUserData: true,
bridgeLegacyTest: true,
Expand All @@ -38,7 +39,8 @@ export const launchSuiteElectronApp = async (params: LaunchSuiteParams = {}) =>
const options = Object.assign(defaultParams, params);

const appDir = path.join(__dirname, '../../../suite-desktop');
const desiredLogLevel = process.env.LOGLEVEL ?? 'error';
const logLevelArgument = `--log-level=${process.env.LOGLEVEL ?? 'error'}`;
const viewportArgument = `--width=${options.viewport.width} --height=${options.viewport.height}`;
if (!options.bridgeDaemon) {
// TODO: #15646 Find out why currently pw fails to see node-bridge so we default to legacy bridge.
await TrezorUserEnvLink.startBridge(LEGACY_BRIDGE_VERSION);
Expand All @@ -49,15 +51,14 @@ export const launchSuiteElectronApp = async (params: LaunchSuiteParams = {}) =>
path.join(appDir, './dist/app.js'),
disableHashCheckArgument,
showDebugMenuArgument,
`--log-level=${desiredLogLevel}`,
viewportArgument,
logLevelArgument,
...(options.bridgeLegacyTest ? ['--bridge-legacy', '--bridge-test'] : []),
...(options.bridgeDaemon ? ['--bridge-daemon', '--skip-new-bridge-rollout'] : []),
],
colorScheme: params.colorScheme,
locale: params.locale,
...(params.videoFolder && {
recordVideo: { dir: params.videoFolder, size: { width: 1280, height: 720 } },
}),
recordVideo: { dir: options.videoFolder, size: options.viewport },
});

const localDataDir = await electronApp.evaluate(({ app }) => app.getPath('userData'));
Expand Down Expand Up @@ -98,7 +99,7 @@ export const launchSuiteElectronApp = async (params: LaunchSuiteParams = {}) =>
return electronApp;
};

export const launchSuite = async (params: LaunchSuiteParams = {}) => {
export const launchSuite = async (params: LaunchSuiteParams) => {
const electronApp = await launchSuiteElectronApp(params);
const window = await electronApp.firstWindow();

Expand Down
15 changes: 4 additions & 11 deletions packages/suite-desktop-core/e2e/support/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,7 @@ const test = base.extend<Fixtures>({
await use(TrezorUserEnvLinkProxy);
},
electronWindow: async (
{
trezorUserEnvLink,
startEmulator,
setupEmulator,
emulatorStartConf,
emulatorSetupConf,
locale,
colorScheme,
},
{ trezorUserEnvLink, startEmulator, setupEmulator, emulatorStartConf, emulatorSetupConf },
use,
testInfo,
) => {
Expand All @@ -96,9 +88,10 @@ const test = base.extend<Fixtures>({

if (isDesktopProject(testInfo)) {
const suite = await launchSuite({
locale,
colorScheme,
locale: testInfo.project.use.locale,
colorScheme: testInfo.project.use.colorScheme,
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
});
await use(suite.window);
await suite.electronApp.close(); // Ensure cleanup after tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ test.describe.serial('Bridge', { tag: ['@group=suite', '@desktopOnly'] }, () =>
await trezorUserEnvLink.stopBridge();
});

test('App in daemon mode spawns bridge', async ({ request }) => {
test('App in daemon mode spawns bridge', async ({ request }, testInfo) => {
const daemonApp = await launchSuiteElectronApp({
bridgeDaemon: true,
bridgeLegacyTest: false,
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
});

await expect(async () => {
await expectBridgeToBeRunning(request);
}).toPass({ timeout: 3_000 });

// launch UI
const suite = await launchSuite();
const suite = await launchSuite({
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
});
const title = await suite.window.title();
expect(title).toContain('Trezor Suite');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ test.describe.serial('Bridge', { tag: ['@group=suite', '@desktopOnly'] }, () =>
});

// #15646 This test is failing and has no values since the launchSuite starts legacy bridge in emulator anyway
test.skip('App spawns bundled bridge and stops it after app quit', async ({ request }) => {
const suite = await launchSuite();
test.skip('App spawns bundled bridge and stops it after app quit', async ({
request,
}, testInfo) => {
const suite = await launchSuite({
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
});
const title = await suite.window.title();
expect(title).toContain('Trezor Suite');

Expand Down Expand Up @@ -51,7 +56,10 @@ test.describe.serial('Bridge', { tag: ['@group=suite', '@desktopOnly'] }, () =>
await trezorUserEnvLink.setupEmu({});
await trezorUserEnvLink.startBridge(LEGACY_BRIDGE_VERSION);

const suite = await launchSuite();
const suite = await launchSuite({
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
});
await suite.window.title();

const devicePrompt = new DevicePromptActions(suite.window);
Expand Down
34 changes: 24 additions & 10 deletions packages/suite-desktop-core/e2e/tests/bridge-thor/spawn-tor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ const turnOnTorInSettings = async (window: Page, shouldEnableTor = true) => {
};

test.describe.skip('Tor loading screen', { tag: ['@group=suite', '@desktopOnly'] }, () => {
test('Tor loading screen: happy path', async () => {
/* eslint-disable-next-line no-empty-pattern */
test('Tor loading screen: happy path', async ({}, testInfo) => {
const suiteArgs = {
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
};
test.setTimeout(timeout);

let suite = await launchSuite();
let suite = await launchSuite(suiteArgs);

await turnOnTorInSettings(suite.window);

suite.electronApp.close();

suite = await launchSuite();
suite = await launchSuite(suiteArgs);

await suite.window.waitForSelector('[data-testid="@tor-loading-screen"]', {
state: 'visible',
Expand All @@ -53,18 +58,22 @@ test.describe.skip('Tor loading screen', { tag: ['@group=suite', '@desktopOnly']
suite.electronApp.close();
});

test('Tor loading screen: making sure that all the request go throw Tor', async () => {
test.setTimeout(timeout);
/* eslint-disable-next-line no-empty-pattern */
test('Tor loading screen: making sure that all the request go throw Tor', async ({}, testInfo) => {
const suiteArgs = {
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
};

const networkAnalyzer = new NetworkAnalyzer();

let suite = await launchSuite();
let suite = await launchSuite(suiteArgs);

await turnOnTorInSettings(suite.window);

suite.electronApp.close();

suite = await launchSuite();
suite = await launchSuite(suiteArgs);
// Start network analyzer after making sure tor is going to be running.
networkAnalyzer.start();

Expand All @@ -82,16 +91,21 @@ test.describe.skip('Tor loading screen', { tag: ['@group=suite', '@desktopOnly']
suite.electronApp.close();
});

test('Tor loading screen: disable tor while loading', async () => {
/* eslint-disable-next-line no-empty-pattern */
test('Tor loading screen: disable tor while loading', async ({}, testInfo) => {
const suiteArgs = {
videoFolder: testInfo.outputDir,
viewport: testInfo.project.use.viewport!,
};
test.setTimeout(timeout);

let suite = await launchSuite();
let suite = await launchSuite(suiteArgs);

await turnOnTorInSettings(suite.window);

suite.electronApp.close();

suite = await launchSuite();
suite = await launchSuite(suiteArgs);

await suite.window.waitForSelector('[data-testid="@tor-loading-screen"]', {
state: 'visible',
Expand Down

0 comments on commit 8d0cee1

Please sign in to comment.