Skip to content

Commit

Permalink
chore(test): refactoring some tests (#9005)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazar <[email protected]>
  • Loading branch information
cbr7 authored Sep 21, 2024
1 parent f655769 commit f9d5d8e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 104 deletions.
17 changes: 5 additions & 12 deletions tests/playwright/src/model/pages/container-details-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ContainerDetailsPage extends DetailsPage {
readonly deleteButton: Locator;
readonly imageLink: Locator;
readonly deployButton: Locator;
readonly startButton: Locator;

static readonly SUMMARY_TAB = 'Summary';
static readonly LOGS_TAB = 'Logs';
Expand All @@ -43,6 +44,7 @@ export class ContainerDetailsPage extends DetailsPage {
this.deleteButton = this.controlActions.getByRole('button').and(this.page.getByLabel('Delete Container'));
this.imageLink = this.header.getByRole('link', { name: 'Image Details' });
this.deployButton = this.controlActions.getByRole('button', { name: 'Deploy to Kubernetes' });
this.startButton = this.controlActions.getByRole('button', { name: 'Start Container', exact: true });
}

async getState(): Promise<string> {
Expand All @@ -54,18 +56,9 @@ export class ContainerDetailsPage extends DetailsPage {
return ContainerState.Unknown;
}

async stopContainer(failIfStopped = false): Promise<void> {
try {
await playExpect.poll(async () => await this.getState()).toBe(ContainerState.Running);
await playExpect(this.stopButton).toBeEnabled();
await this.stopButton.click();
} catch (error) {
if (failIfStopped) {
throw Error(
`Container is not running, its state is: ${await this.getState()}, stop button not available: ${error}`,
);
}
}
async stopContainer(): Promise<void> {
await playExpect(this.stopButton).toBeEnabled();
await this.stopButton.click();
}

async deleteContainer(): Promise<ContainersPage> {
Expand Down
37 changes: 8 additions & 29 deletions tests/playwright/src/model/pages/pods-details-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { expect as playExpect } from '@playwright/test';

import { handleConfirmationDialog } from '../../utility/operations';
import { PodState } from '../core/states';
import { NavigationBar } from '../workbench/navigation';
import { DetailsPage } from './details-page';
import { PodsPage } from './pods-page';

Expand Down Expand Up @@ -57,43 +56,23 @@ export class PodDetailsPage extends DetailsPage {
return PodState.Unknown;
}

async startPod(failIfStarted = false): Promise<void> {
try {
await playExpect(this.startButton).toBeEnabled();
await this.startButton.click();
} catch (error) {
if (failIfStarted) {
throw Error(`Pod is not stopped, its state is: ${await this.getState()}, start button not available: ${error}`);
}
}
async startPod(): Promise<void> {
await playExpect(this.startButton).toBeEnabled({ timeout: 10_000 });
await this.startButton.click();
}

async stopPod(podToRun: string, failIfStopped = false): Promise<void> {
const navigationBar = new NavigationBar(this.page);
const pods = await navigationBar.openPods();
const podDetails = await pods.openPodDetails(podToRun);

await playExpect(podDetails.heading).toBeVisible();
await playExpect(podDetails.heading).toContainText(podToRun);

try {
await playExpect.poll(async () => await this.getState()).toBe(PodState.Running);
await playExpect(this.stopButton).toBeVisible();
await this.stopButton.click();
} catch (error) {
if (failIfStopped) {
throw Error(`Pod is not running, its state is: ${await this.getState()}, stop button not available: ${error}`);
}
}
async stopPod(): Promise<void> {
await playExpect(this.stopButton).toBeEnabled({ timeout: 10_000 });
await this.stopButton.click();
}

async restartPod(): Promise<void> {
await playExpect(this.restartButton).toBeEnabled({ timeout: 20000 });
await playExpect(this.restartButton).toBeEnabled({ timeout: 20_000 });
await this.restartButton.click();
}

async deletePod(): Promise<PodsPage> {
await playExpect(this.deleteButton).toBeEnabled();
await playExpect(this.deleteButton).toBeEnabled({ timeout: 10_000 });
await this.deleteButton.click();
await handleConfirmationDialog(this.page);
return new PodsPage(this.page);
Expand Down
28 changes: 14 additions & 14 deletions tests/playwright/src/model/workbench/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,56 @@ export class NavigationBar {
}

async openDashboard(): Promise<DashboardPage> {
await this.dashboardLink.waitFor({ state: 'visible', timeout: 3000 });
await this.dashboardLink.click({ timeout: 5000 });
await this.dashboardLink.waitFor({ state: 'visible' });
await this.dashboardLink.click();
return new DashboardPage(this.page);
}

async openImages(): Promise<ImagesPage> {
await this.imagesLink.waitFor({ state: 'visible', timeout: 3000 });
await this.imagesLink.click({ timeout: 5000 });
await this.imagesLink.waitFor({ state: 'visible' });
await this.imagesLink.click();
return new ImagesPage(this.page);
}

async openContainers(): Promise<ContainersPage> {
await this.containersLink.waitFor({ state: 'visible', timeout: 3000 });
await this.containersLink.click({ timeout: 5000 });
await this.containersLink.waitFor({ state: 'visible' });
await this.containersLink.click();
return new ContainersPage(this.page);
}

async openPods(): Promise<PodsPage> {
await this.podsLink.waitFor({ state: 'visible', timeout: 3000 });
await this.podsLink.click({ timeout: 5000 });
await this.podsLink.waitFor({ state: 'visible' });
await this.podsLink.click();
return new PodsPage(this.page);
}

async openSettings(): Promise<SettingsBar> {
const settingsBar = new SettingsBar(this.page);
if (!(await settingsBar.settingsNavBar.isVisible())) {
await expect(this.settingsLink).toBeVisible();
await this.settingsLink.click({ timeout: 5000 });
await this.settingsLink.click();
}
return settingsBar;
}

async openVolumes(): Promise<VolumesPage> {
await this.volumesLink.waitFor({ state: 'visible', timeout: 3000 });
await this.volumesLink.click({ timeout: 5000 });
await this.volumesLink.waitFor({ state: 'visible' });
await this.volumesLink.click();
return new VolumesPage(this.page);
}

async openKubernetes(): Promise<KubernetesBar> {
const kubernetesBar = new KubernetesBar(this.page);
if (!(await kubernetesBar.kubernetesNavBar.isVisible())) {
await expect(this.kubernetesLink).toBeVisible();
await this.kubernetesLink.click({ timeout: 5000 });
await this.kubernetesLink.click();
}
return new KubernetesBar(this.page);
}

async openExtensions(): Promise<ExtensionsPage> {
await this.extensionsLink.waitFor({ state: 'visible', timeout: 3000 });
await this.extensionsLink.click({ timeout: 5000 });
await this.extensionsLink.waitFor({ state: 'visible' });
await this.extensionsLink.click();
return new ExtensionsPage(this.page);
}
}
27 changes: 14 additions & 13 deletions tests/playwright/src/specs/container-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>
test.describe.configure({ retries: 2 });

test(`Pulling of '${imageToPull}:${imageTag}' image`, async ({ navigationBar }) => {
test.setTimeout(90000);
test.setTimeout(90_000);

let images = await navigationBar.openImages();
const pullImagePage = await images.openPullImage();
images = await pullImagePage.pullImage(imageToPull, imageTag);

await playExpect.poll(async () => await images.waitForImageExists(imageToPull)).toBeTruthy();
await playExpect.poll(async () => await images.waitForImageExists(imageToPull), { timeout: 10_000 }).toBeTruthy();
});

test(`Start a container '${containerToRun}' from image`, async ({ navigationBar }) => {
Expand All @@ -91,11 +91,11 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>
const containers = await runImage.startContainer(containerToRun, containerStartParams);
await playExpect(containers.header).toBeVisible();
await playExpect
.poll(async () => await containers.containerExists(containerToRun), { timeout: 10000 })
.poll(async () => await containers.containerExists(containerToRun), { timeout: 15_000 })
.toBeTruthy();
const containerDetails = await containers.openContainersDetails(containerToRun);
await playExpect
.poll(async () => await containerDetails.getState(), { timeout: 10000 })
.poll(async () => await containerDetails.getState(), { timeout: 15_000 })
.toContain(ContainerState.Running);

images = await navigationBar.openImages();
Expand Down Expand Up @@ -154,10 +154,9 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>
await containersDetails.stopContainer();

await playExpect
.poll(async () => await containersDetails.getState(), { timeout: 20000 })
.poll(async () => await containersDetails.getState(), { timeout: 30_000 })
.toContain(ContainerState.Exited);
const startButton = containersDetails.getPage().getByRole('button', { name: 'Start Container', exact: true });
await playExpect(startButton).toBeVisible();
await playExpect(containersDetails.startButton).toBeVisible();
});

test(`Start a container from the Containers page`, async ({ navigationBar }) => {
Expand All @@ -173,7 +172,7 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>

await containers.openContainersDetails(containerToRun);
await playExpect
.poll(async () => containersDetails.getState(), { timeout: 20000 })
.poll(async () => containersDetails.getState(), { timeout: 30_000 })
.toContain(ContainerState.Running);
});

Expand All @@ -190,7 +189,7 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>

await containers.openContainersDetails(containerToRun);
await playExpect
.poll(async () => containersDetails.getState(), { timeout: 20000 })
.poll(async () => containersDetails.getState(), { timeout: 30_000 })
.toContain(ContainerState.Exited);
});

Expand All @@ -200,7 +199,9 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>
await playExpect(containersDetails.heading).toContainText(containerToRun);
const containersPage = await containersDetails.deleteContainer();
await playExpect(containersPage.heading).toBeVisible();
await playExpect.poll(async () => await containersPage.containerExists(containerToRun)).toBeFalsy();
await playExpect
.poll(async () => await containersPage.containerExists(containerToRun), { timeout: 10_000 })
.toBeFalsy();
});

test(`Deleting a container from the Containers page`, async ({ navigationBar }) => {
Expand All @@ -211,11 +212,11 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>
const containers = await runImage.startContainer(containerToRun, containerStartParams);
await playExpect(containers.header).toBeVisible();
await playExpect
.poll(async () => await containers.containerExists(containerToRun), { timeout: 10000 })
.poll(async () => await containers.containerExists(containerToRun), { timeout: 10_000 })
.toBeTruthy();
const containerDetails = await containers.openContainersDetails(containerToRun);
await playExpect
.poll(async () => await containerDetails.getState(), { timeout: 10000 })
.poll(async () => await containerDetails.getState(), { timeout: 15_000 })
.toContain(ContainerState.Running);

images = await navigationBar.openImages();
Expand All @@ -226,7 +227,7 @@ test.describe.serial('Verification of container creation workflow @smoke', () =>
const containersPage = await containers.deleteContainer(containerToRun);
await playExpect(containersPage.heading).toBeVisible();
await playExpect
.poll(async () => await containersPage.containerExists(containerToRun), { timeout: 30000 })
.poll(async () => await containersPage.containerExists(containerToRun), { timeout: 30_000 })
.toBeFalsy();
});

Expand Down
Loading

0 comments on commit f9d5d8e

Please sign in to comment.