Skip to content

Commit 497cbe1

Browse files
authored
chore(test): refactoring some tests for better performance (podman-desktop#18150)
* chore(test): refactoring some tests for better performance
1 parent 6f7484f commit 497cbe1

5 files changed

Lines changed: 91 additions & 100 deletions

File tree

tests/playwright/src/model/pages/network-details-page.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ export class NetworkDetailsPage extends DetailsPage {
5959
await playExpect(this.deleteButton).toBeEnabled();
6060
await this.deleteButton.click();
6161
await handleConfirmationDialog(this.page, 'Delete Network?', true, 'Delete');
62+
63+
const errorDialog = this.page.getByRole('dialog', { name: 'Delete Network Failed' });
64+
if (await errorDialog.isVisible({ timeout: 2_000 }).catch(() => false)) {
65+
const errorText = await errorDialog.textContent();
66+
const dismissButton = errorDialog.getByRole('button', { name: 'Dismiss' });
67+
await dismissButton.click();
68+
throw new Error(`Network deletion failed: ${errorText}`);
69+
}
70+
6271
return new NetworksPage(this.page);
6372
});
6473
}

tests/playwright/src/model/pages/networks-page.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ export class NetworksPage extends MainPage {
5656
await playExpect(networkDeleteButton).toBeEnabled();
5757
await networkDeleteButton.click();
5858
await handleConfirmationDialog(this.page, 'Delete Network?', true, 'Delete');
59+
60+
const errorDialog = this.page.getByRole('dialog', { name: 'Delete Network Failed' });
61+
if (await errorDialog.isVisible({ timeout: 2_000 }).catch(() => false)) {
62+
const errorText = await errorDialog.textContent();
63+
const dismissButton = errorDialog.getByRole('button', { name: 'Dismiss' });
64+
await dismissButton.click();
65+
throw new Error(`Network deletion failed: ${errorText}`);
66+
}
67+
5968
return this;
6069
});
6170
}

tests/playwright/src/specs/container-smoke.spec.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,20 @@ import { rmSync } from 'node:fs';
2020
import { tmpdir } from 'node:os';
2121
import path from 'node:path';
2222

23-
import { ContainerState, ImageState, ResourceElementState } from '/@/model/core/states';
23+
import { ContainerState, ImageState } from '/@/model/core/states';
2424
import type { ContainerInteractiveParams } from '/@/model/core/types';
2525
import { ContainersPage } from '/@/model/pages/containers-page';
2626
import { ImageDetailsPage } from '/@/model/pages/image-details-page';
27-
import type { ImagesPage } from '/@/model/pages/images-page';
28-
import { PodmanMachineDetails } from '/@/model/pages/podman-machine-details-page';
29-
import { ResourceConnectionCardPage } from '/@/model/pages/resource-connection-card-page';
30-
import { ResourcesPage } from '/@/model/pages/resources-page';
31-
import { NavigationBar } from '/@/model/workbench/navigation';
3227
import { expect as playExpect, test } from '/@/utility/fixtures';
3328
import { deleteContainer, deleteImage } from '/@/utility/operations';
34-
import { isLinux } from '/@/utility/platform';
35-
import { waitForPodmanMachineStartup, waitWhile } from '/@/utility/wait';
29+
import { waitForPodmanMachineStartup } from '/@/utility/wait';
3630

3731
const imageToPull = 'ghcr.io/linuxcontainers/alpine';
3832
const imageTag = 'latest';
3933
const containerToRun = 'alpine-container';
4034
const containerList = ['first', 'second', 'third'];
4135
const containerStartParamsInteractive: ContainerInteractiveParams = { attachTerminal: true, interactive: true };
4236
const containerStartParams: ContainerInteractiveParams = { attachTerminal: false };
43-
const PODMAN_MACHINE_NAME = 'podman-machine-default';
44-
const PODMAN_MACHINE_VISIBLE_NAME = 'Podman Machine';
45-
const RESOURCE_NAME = 'podman';
4637

4738
test.beforeAll(async ({ runner, welcomePage, page }) => {
4839
test.setTimeout(180_000);
@@ -51,48 +42,6 @@ test.beforeAll(async ({ runner, welcomePage, page }) => {
5142
await welcomePage.handleWelcomePage(true);
5243
await waitForPodmanMachineStartup(page);
5344

54-
// On Windows, stop and restart the machine via the UI to ensure a healthy socket connection
55-
if (!isLinux) {
56-
const navigationBar = new NavigationBar(page);
57-
const settingsBar = await navigationBar.openSettings();
58-
await settingsBar.resourcesTab.click();
59-
60-
const resourcesPage = new ResourcesPage(page);
61-
await playExpect.poll(async () => await resourcesPage.resourceCardIsVisible(RESOURCE_NAME)).toBeTruthy();
62-
63-
const resourcesPodmanConnections = new ResourceConnectionCardPage(page, RESOURCE_NAME, PODMAN_MACHINE_NAME);
64-
await playExpect(resourcesPodmanConnections.resourceElement).toBeVisible({ timeout: 20_000 });
65-
await playExpect(resourcesPodmanConnections.resourceElementDetailsButton).toBeVisible();
66-
await resourcesPodmanConnections.resourceElementDetailsButton.click();
67-
68-
const podmanMachineDetails = new PodmanMachineDetails(page, PODMAN_MACHINE_VISIBLE_NAME);
69-
await playExpect(podmanMachineDetails.podmanMachineStopButton).toBeEnabled({ timeout: 30_000 });
70-
await podmanMachineDetails.podmanMachineStopButton.click();
71-
await playExpect(podmanMachineDetails.podmanMachineStatus).toHaveText(ResourceElementState.Off, {
72-
timeout: 60_000,
73-
});
74-
75-
await playExpect(podmanMachineDetails.podmanMachineStartButton).toBeEnabled();
76-
await podmanMachineDetails.podmanMachineStartButton.click();
77-
await playExpect(podmanMachineDetails.podmanMachineStatus).toHaveText(ResourceElementState.Running, {
78-
timeout: 90_000,
79-
});
80-
}
81-
82-
let images: ImagesPage;
83-
try {
84-
images = await new NavigationBar(page).openImages();
85-
} catch (error) {
86-
await runner.screenshot('error-on-open-images.png');
87-
throw error;
88-
}
89-
90-
await waitWhile(async () => await images.pageIsEmpty(), {
91-
timeout: 60_000,
92-
sendError: false,
93-
message: 'Images page is empty, there are no images present',
94-
});
95-
9645
try {
9746
await deleteContainer(page, containerToRun);
9847
} catch (error) {

tests/playwright/src/specs/enhanced-dashboard.spec.ts

Lines changed: 70 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ import { waitForPodmanMachineStartup } from '/@/utility/wait';
3535
const PODMAN_MACHINE_NAME: string = 'podman-machine-default';
3636
const PODMAN_MACHINE_VISIBLE_NAME: string = 'Podman Machine';
3737

38+
const TIMEOUT_SHORT = 10_000;
39+
const TIMEOUT_STANDARD = 30_000;
40+
const TIMEOUT_SETUP = 120_000;
41+
const PODMAN_MACHINE_STARTUP_TIMEOUT = 300_000;
42+
const TIMEOUT_CREATE_MACHINE_TEST = 320_000;
43+
3844
test.skip(
3945
isLinux || process.env.TEST_PODMAN_MACHINE !== 'true',
4046
'Tests suite should not run on Linux platform or if TEST_PODMAN_MACHINE is not true',
4147
);
4248

4349
test.beforeAll(async ({ runner, welcomePage, page }) => {
44-
test.setTimeout(120_000);
50+
test.setTimeout(TIMEOUT_SETUP);
4551
runner.setVideoAndTraceName('enhanced-dashboard-e2e');
4652
await welcomePage.handleWelcomePage(true);
4753

@@ -52,7 +58,7 @@ test.beforeAll(async ({ runner, welcomePage, page }) => {
5258
});
5359

5460
test.afterAll(async ({ runner, page }) => {
55-
test.setTimeout(120_000);
61+
test.setTimeout(TIMEOUT_SETUP);
5662

5763
try {
5864
if (test.info().status === 'failed') {
@@ -70,75 +76,93 @@ test.afterAll(async ({ runner, page }) => {
7076
test.describe
7177
.serial('Enhanced dashboard experimental feature', { tag: ['@experimental'] }, () => {
7278
test('Enable/disable experimental feature', async ({ navigationBar, page }) => {
73-
// assert assets state before enabling it (disabled by default for the time being)
74-
await setEnhancedDashboardFeature(page, navigationBar, false);
75-
let dashboardPage = await waitForDashboardState(navigationBar, false);
76-
await playExpect(dashboardPage.systemOverviewButton).not.toBeVisible();
77-
await playExpect(dashboardPage.podmanProvider).toBeVisible({ timeout: 10_000 });
78-
await dashboardPage.podmanProvider.scrollIntoViewIfNeeded();
79-
// enable the feature
80-
await setEnhancedDashboardFeature(page, navigationBar, true);
81-
dashboardPage = await waitForDashboardState(navigationBar, true);
82-
// assert assets state after enabling it
83-
await playExpect(dashboardPage.systemOverviewButton).toBeEnabled();
84-
await dashboardPage.expandSystemOverview(true);
85-
await playExpect(dashboardPage.systemOverview).toBeVisible({ timeout: 10_000 });
86-
await playExpect(dashboardPage.podmanProvider).not.toBeVisible();
87-
await playExpect(dashboardPage.statusButton).toBeEnabled();
88-
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Stopped);
89-
await playExpect(dashboardPage.noContainerEngineLabel).toBeVisible();
90-
await playExpect(dashboardPage.setUpPodmanButton).toBeEnabled();
91-
// disable the feature and assert everything went back to the expected state
92-
await setEnhancedDashboardFeature(page, navigationBar, false);
93-
dashboardPage = await waitForDashboardState(navigationBar, false);
94-
await playExpect(dashboardPage.systemOverviewButton).not.toBeVisible();
95-
await dashboardPage.podmanProvider.scrollIntoViewIfNeeded();
79+
await test.step('Verify feature is disabled by default', async () => {
80+
await setEnhancedDashboardFeature(page, navigationBar, false);
81+
const dashboardPage = await waitForDashboardState(navigationBar, false);
82+
await playExpect(dashboardPage.systemOverviewButton).not.toBeVisible();
83+
await playExpect(dashboardPage.podmanProvider).toBeVisible({ timeout: TIMEOUT_SHORT });
84+
await dashboardPage.podmanProvider.scrollIntoViewIfNeeded();
85+
});
86+
87+
await test.step('Enable feature and verify system overview appears', async () => {
88+
await setEnhancedDashboardFeature(page, navigationBar, true);
89+
const dashboardPage = await waitForDashboardState(navigationBar, true);
90+
await playExpect(dashboardPage.systemOverviewButton).toBeEnabled();
91+
await dashboardPage.expandSystemOverview(true);
92+
await playExpect(dashboardPage.systemOverview).toBeVisible({ timeout: TIMEOUT_SHORT });
93+
await playExpect(dashboardPage.podmanProvider).not.toBeVisible();
94+
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Stopped);
95+
await playExpect(dashboardPage.noContainerEngineLabel).toBeVisible();
96+
await playExpect(dashboardPage.setUpPodmanButton).toBeEnabled();
97+
});
98+
99+
await test.step('Disable feature and verify dashboard reverts', async () => {
100+
await setEnhancedDashboardFeature(page, navigationBar, false);
101+
const dashboardPage = await waitForDashboardState(navigationBar, false);
102+
await playExpect(dashboardPage.systemOverviewButton).not.toBeVisible();
103+
await playExpect(dashboardPage.podmanProvider).toBeVisible({ timeout: TIMEOUT_SHORT });
104+
});
96105
});
97106

98107
test('Create Podman machine from Dashboard', async ({ page, navigationBar }) => {
99-
test.setTimeout(320_000);
108+
test.setTimeout(TIMEOUT_CREATE_MACHINE_TEST);
100109

101-
await test.step('Open dashboard and initialize Podman machine', async () => {
102-
// enable the feature
110+
await test.step('Create machine from system overview', async () => {
103111
await setEnhancedDashboardFeature(page, navigationBar, true);
104-
let dashboardPage = await waitForDashboardState(navigationBar, true);
112+
const dashboardPage = await waitForDashboardState(navigationBar, true);
105113
await dashboardPage.createPodmanMachineFromSystemOverview(PODMAN_MACHINE_NAME, {
106114
isRootful: false,
107115
enableUserNet: false,
108116
startNow: true,
109117
virtualizationProvider: getVirtualizationProvider(),
110118
});
111-
// systemOverview button -> starting up; status label -> starting (missing aria-label)
112-
dashboardPage = await navigationBar.openDashboard();
119+
});
120+
121+
await test.step('Wait for machine to reach operational state', async () => {
122+
const dashboardPage = await navigationBar.openDashboard();
113123
await dashboardPage.statusButton.scrollIntoViewIfNeeded();
114-
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Starting, { timeout: 300_000 });
115-
// systemOverview button -> systems operational; status label -> running (missing aria-label)
124+
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Starting, {
125+
timeout: PODMAN_MACHINE_STARTUP_TIMEOUT,
126+
});
116127
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Operational, {
117-
timeout: 300_000,
128+
timeout: PODMAN_MACHINE_STARTUP_TIMEOUT,
118129
});
119-
// click on 'status' button to go to podman machine in settings/resources
130+
});
131+
132+
await test.step('Navigate to resources via status button', async () => {
133+
const dashboardPage = await navigationBar.openDashboard();
134+
await dashboardPage.statusButton.scrollIntoViewIfNeeded();
120135
await playExpect(dashboardPage.statusButton).toBeEnabled();
121136
await dashboardPage.statusButton.click();
122-
let resourcesPage = new ResourcesPage(page);
137+
const resourcesPage = new ResourcesPage(page);
123138
await playExpect
124-
.poll(async () => resourcesPage.resourceCardIsVisible('podman'), { timeout: 30_000 })
139+
.poll(async () => resourcesPage.resourceCardIsVisible('podman'), { timeout: TIMEOUT_STANDARD })
125140
.toBeTruthy();
126141
const resourcesPodmanConnections = new ResourceConnectionCardPage(page, 'podman', PODMAN_MACHINE_NAME);
127-
await playExpect(resourcesPodmanConnections.providerConnections).toBeVisible({ timeout: 10_000 });
128-
// stop machine
142+
await playExpect(resourcesPodmanConnections.providerConnections).toBeVisible({ timeout: TIMEOUT_SHORT });
143+
});
144+
145+
await test.step('Stop machine and verify dashboard reflects stopped state', async () => {
146+
const resourcesPodmanConnections = new ResourceConnectionCardPage(page, 'podman', PODMAN_MACHINE_NAME);
129147
await resourcesPodmanConnections.performConnectionAction(ResourceElementActions.Stop);
130-
// come back to dashboard, button -> some systems are stopped
131-
await navigationBar.openDashboard();
148+
const dashboardPage = await navigationBar.openDashboard();
132149
await dashboardPage.statusButton.scrollIntoViewIfNeeded();
133-
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Stopped, { timeout: 10_000 });
134-
// click on 'navigate to...' button, verify it goes to machine details
150+
await playExpect(dashboardPage.statusButton).toHaveText(SystemOverviewState.Stopped, {
151+
timeout: TIMEOUT_SHORT,
152+
});
153+
});
154+
155+
await test.step('Verify resource details navigation', async () => {
156+
const dashboardPage = await navigationBar.openDashboard();
135157
await dashboardPage.checkSystemOverviewResourceDetails(PODMAN_MACHINE_VISIBLE_NAME);
136-
// come back to dashboard, click on status button, verify it goes to resources
137-
await navigationBar.openDashboard();
158+
});
159+
160+
await test.step('Verify status button navigates to resources page', async () => {
161+
const dashboardPage = await navigationBar.openDashboard();
138162
await dashboardPage.statusButton.scrollIntoViewIfNeeded();
139163
await playExpect(dashboardPage.statusButton).toBeEnabled();
140164
await dashboardPage.statusButton.click();
141-
resourcesPage = new ResourcesPage(page);
165+
const resourcesPage = new ResourcesPage(page);
142166
await playExpect(resourcesPage.header).toBeVisible();
143167
});
144168
});

tests/playwright/src/specs/network-smoke.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ test.describe
113113

114114
// Wait for container row to appear, then open details and verify it is running
115115
await playExpect
116-
.poll(async () => await containersPage.getContainerRowByName(testContainerName), { timeout: 30_000 })
116+
.poll(async () => await containersPage.getContainerRowByName(testContainerName), { timeout: 60_000 })
117117
.toBeTruthy();
118118
const containerDetails = await containersPage.openContainersDetails(testContainerName);
119119
await playExpect(containerDetails.heading).toContainText(testContainerName);

0 commit comments

Comments
 (0)