Skip to content

Commit

Permalink
chore(test): initial draft for test.step (podman-desktop#9613)
Browse files Browse the repository at this point in the history
chore(test): implement test.step in the entire test framework

Signed-off-by: Vladimir Lazar <[email protected]>
  • Loading branch information
cbr7 authored Oct 28, 2024
1 parent 21368a2 commit 16363c5
Show file tree
Hide file tree
Showing 36 changed files with 1,159 additions and 802 deletions.
1 change: 0 additions & 1 deletion tests/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export * from './globalSetup/global-setup';
export * from './runner/podman-desktop-runner';
export * from './runner/runner-options';
export * from './setupFiles/setup-registry';
export type { RunnerTestContext } from './testContext/runner-test-context';
export * from './utility/cleanup';
export * from './utility/fixtures';
export * from './utility/operations';
Expand Down
92 changes: 48 additions & 44 deletions tests/playwright/src/model/pages/build-image-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import type { Locator, Page } from '@playwright/test';
import { expect as playExpect } from '@playwright/test';
import test, { expect as playExpect } from '@playwright/test';

import { ArchitectureType } from '../core/platforms';
import { BasePage } from './base-page';
Expand All @@ -38,14 +38,18 @@ export class BuildImagePage extends BasePage {

constructor(page: Page) {
super(page);
this.heading = page.getByRole('heading', { name: 'Build Image from Containerfile' });
this.heading = page.getByRole('heading', {
name: 'Build Image from Containerfile',
});
this.containerFilePathInput = page.getByPlaceholder('Containerfile to build');
this.buildContextDirectoryInput = page.getByPlaceholder('Directory to build in');
this.imageNameInput = page.getByPlaceholder('my-custom-image');
this.buildButton = page.getByRole('button', { name: 'Build', exact: true });
this.doneButton = page.getByRole('button', { name: 'Done' });
this.containerFilePathButton = page.getByRole('button', { name: 'Browse...' }).first();
this.platformRegion = page.getByRole('region', { name: 'Build Platform Options' });
this.platformRegion = page.getByRole('region', {
name: 'Build Platform Options',
});
this.arm64Button = this.platformRegion.getByLabel('linux/arm64');
this.amd64Button = this.platformRegion.getByLabel('linux/amd64');
this.arm64checkbox = this.platformRegion.getByLabel('ARM® aarch64 systems');
Expand All @@ -59,57 +63,57 @@ export class BuildImagePage extends BasePage {
archType: string = ArchitectureType.Default,
timeout = 120000,
): Promise<ImagesPage> {
console.log(
`Building image ${imageName} from ${containerFilePath} in ${contextDirectory} with ${archType} architecture`,
);

if (!containerFilePath) {
throw Error(`Path to containerfile is incorrect or not provided!`);
}
return test.step(`Building image ${imageName} from ${containerFilePath} in ${contextDirectory} with ${archType} architecture`, async () => {
if (!containerFilePath) {
throw Error(`Path to containerfile is incorrect or not provided!`);
}

await this.containerFilePathInput.fill(containerFilePath);
await this.containerFilePathInput.fill(containerFilePath);

if (contextDirectory) await this.buildContextDirectoryInput.fill(contextDirectory);
if (imageName) {
await this.imageNameInput.clear();
await this.imageNameInput.pressSequentially(imageName, { delay: 50 });
}
if (contextDirectory) await this.buildContextDirectoryInput.fill(contextDirectory);
if (imageName) {
await this.imageNameInput.clear();
await this.imageNameInput.pressSequentially(imageName, { delay: 50 });
}

if (archType !== ArchitectureType.Default) {
await this.uncheckedAllCheckboxes();
if (archType !== ArchitectureType.Default) {
await this.uncheckedAllCheckboxes();

switch (archType) {
case ArchitectureType.ARM64:
await this.arm64Button.click();
await playExpect(this.arm64checkbox).toBeChecked();
break;
case ArchitectureType.AMD64:
await this.amd64Button.click();
await playExpect(this.amd64checkbox).toBeChecked();
break;
switch (archType) {
case ArchitectureType.ARM64:
await this.arm64Button.click();
await playExpect(this.arm64checkbox).toBeChecked();
break;
case ArchitectureType.AMD64:
await this.amd64Button.click();
await playExpect(this.amd64checkbox).toBeChecked();
break;
}
}
}

await playExpect(this.buildButton).toBeEnabled();
await this.buildButton.scrollIntoViewIfNeeded();
await this.buildButton.click();
await playExpect(this.buildButton).toBeEnabled();
await this.buildButton.scrollIntoViewIfNeeded();
await this.buildButton.click();

await playExpect(this.doneButton).toBeEnabled({ timeout: timeout });
await this.doneButton.scrollIntoViewIfNeeded();
await this.doneButton.click();
console.log(`Image ${imageName} has been built successfully!`);
await playExpect(this.doneButton).toBeEnabled({ timeout: timeout });
await this.doneButton.scrollIntoViewIfNeeded();
await this.doneButton.click();
console.log(`Image ${imageName} has been built successfully!`);

return new ImagesPage(this.page);
return new ImagesPage(this.page);
});
}

async uncheckedAllCheckboxes(): Promise<void> {
if (await this.arm64checkbox.isChecked()) {
await this.arm64Button.click();
await playExpect(this.arm64checkbox).not.toBeChecked();
}
if (await this.amd64checkbox.isChecked()) {
await this.amd64Button.click();
await playExpect(this.amd64checkbox).not.toBeChecked();
}
return test.step('Uncheck all checkboxes', async () => {
if (await this.arm64checkbox.isChecked()) {
await this.arm64Button.click();
await playExpect(this.arm64checkbox).not.toBeChecked();
}
if (await this.amd64checkbox.isChecked()) {
await this.amd64Button.click();
await playExpect(this.amd64checkbox).not.toBeChecked();
}
});
}
}
37 changes: 22 additions & 15 deletions tests/playwright/src/model/pages/cli-tools-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import { expect as playExpect } from '@playwright/test';
import test, { expect as playExpect } from '@playwright/test';
import type { Locator, Page } from 'playwright';

import { SettingsPage } from './settings-page';
Expand All @@ -34,7 +34,10 @@ export class CLIToolsPage extends SettingsPage {
super(page, 'CLI Tools');
this.main = page.getByRole('region', { name: 'CLI Tools' }); //check name
this.header = this.main.getByRole('region', { name: 'Header' });
this.heading = this.header.getByRole('heading', { name: 'CLI Tools', exact: true });
this.heading = this.header.getByRole('heading', {
name: 'CLI Tools',
exact: true,
});
this.content = this.main.getByRole('region', { name: 'Content' });
this.toolsTable = this.content.getByRole('table', { name: 'cli-tools' });
this.dropDownDialog = page.getByRole('dialog', {
Expand Down Expand Up @@ -64,24 +67,28 @@ export class CLIToolsPage extends SettingsPage {
}

public async getCurrentToolVersion(toolName: string): Promise<string> {
if ((await this.getToolRow(toolName).getByLabel('no-cli-version', { exact: true }).count()) > 0) {
return '';
}
return test.step(`Get current version of ${toolName}`, async () => {
if ((await this.getToolRow(toolName).getByLabel('no-cli-version', { exact: true }).count()) > 0) {
return '';
}

return await this.getToolRow(toolName).getByLabel('cli-version', { exact: true }).innerText();
return await this.getToolRow(toolName).getByLabel('cli-version', { exact: true }).innerText();
});
}

public async installTool(toolName: string, version: string = ''): Promise<this> {
await playExpect(this.getInstallButton(toolName)).toBeEnabled();
await this.getInstallButton(toolName).click();
await playExpect(this.dropDownDialog).toBeVisible();
if (!version) {
version = await this.getLatestVersionNumber();
}
return test.step(`Install ${toolName}`, async () => {
await playExpect(this.getInstallButton(toolName)).toBeEnabled();
await this.getInstallButton(toolName).click();
await playExpect(this.dropDownDialog).toBeVisible();
if (!version) {
version = await this.getLatestVersionNumber();
}

await playExpect(this.getVersionSelectionButton(version)).toBeEnabled();
await this.getVersionSelectionButton(version).click();
return this;
await playExpect(this.getVersionSelectionButton(version)).toBeEnabled();
await this.getVersionSelectionButton(version).click();
return this;
});
}

private async getLatestVersionNumber(): Promise<string> {
Expand Down
61 changes: 38 additions & 23 deletions tests/playwright/src/model/pages/container-details-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
***********************************************************************/

import type { Locator, Page } from '@playwright/test';
import { expect as playExpect } from '@playwright/test';
import test, { expect as playExpect } from '@playwright/test';

import { handleConfirmationDialog } from '../../utility/operations';
import { ContainerState } from '../core/states';
Expand All @@ -43,43 +43,58 @@ export class ContainerDetailsPage extends DetailsPage {
this.stopButton = this.controlActions.getByRole('button').and(this.page.getByLabel('Stop Container'));
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 });
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> {
const currentState = await this.header.getByRole('status').getAttribute('title');
for (const state of Object.values(ContainerState)) {
if (currentState === state) return state;
}
return test.step('Get container state', async () => {
const currentState = await this.header.getByRole('status').getAttribute('title');
for (const state of Object.values(ContainerState)) {
if (currentState === state) return state;
}

return ContainerState.Unknown;
return ContainerState.Unknown;
});
}

async stopContainer(): Promise<void> {
await playExpect(this.stopButton).toBeEnabled();
await this.stopButton.click();
return test.step('Stop container', async () => {
await playExpect(this.stopButton).toBeEnabled();
await this.stopButton.click();
});
}

async deleteContainer(): Promise<ContainersPage> {
await playExpect(this.deleteButton).toBeEnabled();
await this.deleteButton.click();
await handleConfirmationDialog(this.page);
return new ContainersPage(this.page);
return test.step('Delete container', async () => {
await playExpect(this.deleteButton).toBeEnabled();
await this.deleteButton.click();
await handleConfirmationDialog(this.page);
return new ContainersPage(this.page);
});
}

async getContainerPort(): Promise<string> {
await this.activateTab(ContainerDetailsPage.SUMMARY_TAB);
const summaryTable = this.tabContent.getByRole('table');
const portsRow = summaryTable.locator('tr:has-text("Ports")');
const portsCell = portsRow.getByRole('cell').nth(1);
await playExpect(portsCell).toBeVisible();
return await portsCell.innerText();
return test.step('Get container port', async () => {
await this.activateTab(ContainerDetailsPage.SUMMARY_TAB);
const summaryTable = this.tabContent.getByRole('table');
const portsRow = summaryTable.locator('tr:has-text("Ports")');
const portsCell = portsRow.getByRole('cell').nth(1);
await playExpect(portsCell).toBeVisible();
return await portsCell.innerText();
});
}

async openDeployToKubernetesPage(): Promise<DeployToKubernetesPage> {
await playExpect(this.deployButton).toBeVisible();
await this.deployButton.click();
return new DeployToKubernetesPage(this.page);
return test.step('Open Deploy to Kubernetes page', async () => {
await playExpect(this.deployButton).toBeVisible();
await this.deployButton.click();
return new DeployToKubernetesPage(this.page);
});
}
}
Loading

0 comments on commit 16363c5

Please sign in to comment.