Skip to content

Commit

Permalink
fix(e2e): Disable snapshots for Desktop project
Browse files Browse the repository at this point in the history
minor refactoring and tuning of buy-coin.tests.ts
  • Loading branch information
Vere-Grey committed Dec 21, 2024
1 parent eb3f255 commit c5407ee
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/suite-desktop-core/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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 All @@ -43,7 +45,7 @@ const config: PlaywrightTestConfig = {
snapshotPathTemplate: 'snapshots/{projectName}/{testFilePath}/{arg}{ext}',
expect: {
toHaveScreenshot: {
maxDiffPixelRatio: 0.025,
maxDiffPixelRatio: 0.001,
},
},
};
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
9 changes: 7 additions & 2 deletions packages/suite-desktop-core/e2e/support/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ export const launchSuite = async (params: LaunchSuiteParams = {}) => {
return { electronApp, window };
};

export const isDesktopProject = (testInfo: TestInfo) =>
testInfo.project.name === PlaywrightProjects.Desktop;

export const isWebProject = (testInfo: TestInfo) =>
testInfo.project.name === PlaywrightProjects.Web;

export const getApiUrl = (webBaseUrl: string | undefined, testInfo: TestInfo) => {
const electronApiURL = 'file:///';
const apiURL =
testInfo.project.name === PlaywrightProjects.Desktop ? electronApiURL : webBaseUrl;
const apiURL = isDesktopProject(testInfo) ? electronApiURL : webBaseUrl;
if (!apiURL) {
throw new Error('apiURL is not defined');
}
Expand Down
5 changes: 2 additions & 3 deletions packages/suite-desktop-core/e2e/support/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
} from '@trezor/trezor-user-env-link';

import { DashboardActions } from './pageActions/dashboardActions';
import { getApiUrl, getElectronVideoPath, launchSuite } from './common';
import { getApiUrl, getElectronVideoPath, isDesktopProject, launchSuite } from './common';
import { SettingsActions } from './pageActions/settingsActions';
import { SuiteGuide } from './pageActions/suiteGuideActions';
import { WalletActions } from './pageActions/walletActions';
import { OnboardingActions } from './pageActions/onboardingActions';
import { PlaywrightProjects } from '../playwright.config';
import { AnalyticsFixture } from './analytics';
import { BackupActions } from './pageActions/backupActions';
import { DevicePromptActions } from './pageActions/devicePromptActions';
Expand Down Expand Up @@ -85,7 +84,7 @@ const test = base.extend<Fixtures>({
await trezorUserEnvLink.setupEmu(emulatorSetupConf);
}

if (testInfo.project.name === PlaywrightProjects.Desktop) {
if (isDesktopProject(testInfo)) {
const suite = await launchSuite({
locale,
colorScheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ export class MarketActions {
};

waitForOffersSyncToFinish = async () => {
await expect(this.offerSpinner).toBeVisible();
await expect(this.offerSpinner).toBeHidden({ timeout: 30000 });
};

setYouPayAmount = async (amount: string) => {
//Warning: the field is initialized empty and gets default value after the first offer sync
await expect(this.youPayInput).not.toHaveValue('');
await this.waitForOffersSyncToFinish();
await expect(this.offerSpinner).toBeHidden({ timeout: 30000 });
await this.youPayInput.fill(amount);
//Warning: Bug #16054, as a workaround we wait for offer sync after setting the amount
await this.waitForOffersSyncToFinish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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 { PlaywrightProjects } from '../../playwright.config';
import { AnalyticsActions } from './analyticsActions';
import { isWebProject } from '../common';

export class OnboardingActions {
readonly welcomeTitle: Locator;
Expand Down Expand Up @@ -86,7 +86,7 @@ export class OnboardingActions {

async disableFirmwareHashCheck() {
// Desktop starts with already disabled firmware hash check. Web needs to disable it.
if (this.testInfo.project.name !== PlaywrightProjects.Web) {
if (!isWebProject(this.testInfo)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.describe('Coin market buy', { tag: ['@group=other'] }, () => {

test('Buy crypto from compared offers', async ({ marketPage }) => {
await test.step('Fill input amount and opens offer comparison', async () => {
await marketPage.setYouPayAmount('500');
await marketPage.setYouPayAmount('1234');
await expect(marketPage.layout).toHaveScreenshot('buy-coins-layout.png', {
mask: [marketPage.bestOfferAmount, marketPage.bestOfferProvider],
});
Expand All @@ -39,12 +39,12 @@ test.describe('Coin market buy', { tag: ['@group=other'] }, () => {
);
// TOOD: #16041 Once solved, Assert mocked price
await expect(marketPage.tradeConfirmationCryptoAmount).toHaveText(regexpBtcValue);
await expect(marketPage.tradeConfirmationContinueButton).toBeEnabled();
});
await expect(marketPage.tradeConfirmationContinueButton).toBeEnabled();
});

test('Buy crypto from best offer', async ({ marketPage }) => {
await marketPage.setYouPayAmount('500');
await marketPage.setYouPayAmount('1234');
const { amount, provider } = await marketPage.readBestOfferValues();
await marketPage.buyBestOfferButton.click();
await marketPage.confirmTrade();
Expand Down

0 comments on commit c5407ee

Please sign in to comment.