Skip to content

Commit

Permalink
Refactor pd runner and rename (#8764)
Browse files Browse the repository at this point in the history
* chore(test): refactor pdRunner and create runnerOptions
Signed-off-by: Vladimir Lazar <[email protected]>
  • Loading branch information
cbr7 authored Sep 5, 2024
1 parent 4c147ed commit 38937a9
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 118 deletions.
1 change: 1 addition & 0 deletions tests/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// export core modules
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';
Expand Down
51 changes: 18 additions & 33 deletions tests/playwright/src/runner/podman-desktop-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import { _electron as electron, test } from '@playwright/test';
import type { BrowserWindow } from 'electron';

import { waitWhile } from '../utility/wait';
import { RunnerOptions } from './runner-options';

type WindowState = {
isVisible: boolean;
isDevToolsOpened: boolean;
isCrashed: boolean;
};

export class PodmanDesktopRunner {
export class Runner {
private _options: object;
private _running: boolean;
private _app: ElectronApplication | undefined;
Expand All @@ -40,49 +41,33 @@ export class PodmanDesktopRunner {
private readonly _customFolder;
private readonly _testOutput: string;
private _videoAndTraceName: string | undefined;
private _customSettingsObject: { [key: string]: unknown } = {};
private _runnerOptions: RunnerOptions;

private static _instance: PodmanDesktopRunner | undefined;
private static _instance: Runner | undefined;

static async getInstance({
profile = '',
customFolder = 'podman-desktop',
customSettingsObject = {
'preferences.OpenDevTools': 'none',
'extensions.autoUpdate': true,
'extensions.autoCheckUpdates': true,
},
runnerOptions = new RunnerOptions(),
}: {
profile?: string;
customFolder?: string;
customSettingsObject?: { [key: string]: unknown };
} = {}): Promise<PodmanDesktopRunner> {
if (!PodmanDesktopRunner._instance) {
PodmanDesktopRunner._instance = new PodmanDesktopRunner({ profile, customFolder, customSettingsObject });
await PodmanDesktopRunner._instance.start();
runnerOptions?: RunnerOptions;
} = {}): Promise<Runner> {
if (!Runner._instance) {
Runner._instance = new Runner({ runnerOptions });
await Runner._instance.start();
}
return PodmanDesktopRunner._instance;
return Runner._instance;
}

private constructor({
profile = '',
customFolder = 'podman-desktop',
customSettingsObject = {
'preferences.OpenDevTools': 'none',
'extensions.autoUpdate': true,
'extensions.autoCheckUpdates': true,
},
runnerOptions = new RunnerOptions(),
}: {
profile?: string;
customFolder?: string;
customSettingsObject?: { [key: string]: unknown };
runnerOptions?: RunnerOptions;
} = {}) {
this._running = false;
this._profile = profile;
this._runnerOptions = runnerOptions;
this._profile = this._runnerOptions._profile;
this._testOutput = join('tests', 'playwright', 'output', this._profile);
this._customFolder = join(this._testOutput, customFolder);
this._customFolder = join(this._testOutput, this._runnerOptions._customFolder);
this._videoAndTraceName = undefined;
this._customSettingsObject = customSettingsObject;

// Options setting always needs to be last action in constructor in order to apply settings correctly
this._options = this.defaultOptions();
Expand Down Expand Up @@ -243,7 +228,7 @@ export class PodmanDesktopRunner {
}
}
this._running = false;
PodmanDesktopRunner._instance = undefined;
Runner._instance = undefined;

if (this._videoAndTraceName) {
const videoPath = join(this._testOutput, 'videos', `${this._videoAndTraceName}.webm`);
Expand Down Expand Up @@ -345,7 +330,7 @@ export class PodmanDesktopRunner {
mkdirSync(parentDir, { recursive: true });
}

const settingsContent = JSON.stringify(this._customSettingsObject);
const settingsContent = this._runnerOptions.createSettingsJson();

// write the file
console.log(`disabling OpenDevTools in configuration file ${settingsFile}`);
Expand Down
74 changes: 74 additions & 0 deletions tests/playwright/src/runner/runner-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**********************************************************************
* Copyright (C) 2023-2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export class RunnerOptions {
public readonly _profile: string;
public readonly _customFolder: string;
public readonly _openDevTools: string;
public readonly _autoUpdate: boolean;
public readonly _autoCheckUpdates: boolean;
public readonly _extesionsDisabled: string[];
public readonly _binaryPath: string | undefined;

constructor({
profile = '',
customFolder = 'podman-desktop',
openDevTools = 'none',
autoUpdate = true,
autoCheckUpdates = true,
extesionsDisabled = [],
binaryPath = undefined,
}: {
profile?: string;
customFolder?: string;
openDevTools?: string;
autoUpdate?: boolean;
autoCheckUpdates?: boolean;
extesionsDisabled?: string[];
binaryPath?: string;
} = {}) {
this._profile = profile;
this._customFolder = customFolder;
this._openDevTools = openDevTools;
this._autoUpdate = autoUpdate;
this._autoCheckUpdates = autoCheckUpdates;
this._extesionsDisabled = extesionsDisabled;
this._binaryPath = binaryPath;
}

public createSettingsJson(): string {
console.log(`Binary path: ${this._binaryPath}`);

if (this._binaryPath) {
return JSON.stringify({
'preferences.OpenDevTools': this._openDevTools,
'extensions.autoUpdate': this._autoUpdate,
'extensions.autoCheckUpdates': this._autoCheckUpdates,
'extensions.disabled': this._extesionsDisabled,
'podman.binary.path': this._binaryPath,
});
}

return JSON.stringify({
'preferences.OpenDevTools': this._openDevTools,
'extensions.autoUpdate': this._autoUpdate,
'extensions.autoCheckUpdates': this._autoCheckUpdates,
'extensions.disabled': this._extesionsDisabled,
});
}
}
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/compose-onboarding-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const composePartialInstallation = process.env.COMPOSE_PARTIAL_INSTALL ? process

test.skip(!!isCI && isLinux, 'Tests suite should not run on Linux platform');

test.beforeAll(async ({ pdRunner, welcomePage }) => {
pdRunner.setVideoAndTraceName('compose-onboarding-e2e');
test.beforeAll(async ({ runner, welcomePage }) => {
runner.setVideoAndTraceName('compose-onboarding-e2e');
await welcomePage.handleWelcomePage(true);
});

test.afterAll(async ({ pdRunner }) => {
await pdRunner.close();
test.afterAll(async ({ runner }) => {
await runner.close();
});

test.describe.serial('Compose onboarding workflow verification @smoke', () => {
Expand Down
12 changes: 6 additions & 6 deletions tests/playwright/src/specs/container-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ const containerToRun = 'alpine-container';
const containerList = ['first', 'second', 'third'];
const containerStartParams: ContainerInteractiveParams = { attachTerminal: false };

test.beforeAll(async ({ pdRunner, welcomePage, page }) => {
pdRunner.setVideoAndTraceName('containers-e2e');
test.beforeAll(async ({ runner, welcomePage, page }) => {
runner.setVideoAndTraceName('containers-e2e');
await welcomePage.handleWelcomePage(true);
await waitForPodmanMachineStartup(page);
// wait giving a time to podman desktop to load up
let images: ImagesPage;
try {
images = await new NavigationBar(page).openImages();
} catch (error) {
await pdRunner.screenshot('error-on-open-images.png');
await runner.screenshot('error-on-open-images.png');
throw error;
}
await waitWhile(async () => await images.pageIsEmpty(), {
Expand All @@ -51,12 +51,12 @@ test.beforeAll(async ({ pdRunner, welcomePage, page }) => {
try {
await deleteContainer(page, containerToRun);
} catch (error) {
await pdRunner.screenshot('error-on-open-containers.png');
await runner.screenshot('error-on-open-containers.png');
throw error;
}
});

test.afterAll(async ({ pdRunner, page }) => {
test.afterAll(async ({ runner, page }) => {
test.setTimeout(90000);

try {
Expand All @@ -67,7 +67,7 @@ test.afterAll(async ({ pdRunner, page }) => {

await deleteImage(page, imageToPull);
} finally {
await pdRunner.close();
await runner.close();
}
});

Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/deploy-to-kubernetes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const CONTAINER_START_PARAMS: ContainerInteractiveParams = { attachTerminal: fal

const skipKindInstallation = process.env.SKIP_KIND_INSTALL ? process.env.SKIP_KIND_INSTALL : false;

test.beforeAll(async ({ pdRunner, welcomePage, page }) => {
test.beforeAll(async ({ runner, welcomePage, page }) => {
test.setTimeout(250000);
pdRunner.setVideoAndTraceName('kind-e2e');
runner.setVideoAndTraceName('kind-e2e');

await welcomePage.handleWelcomePage(true);
await waitForPodmanMachineStartup(page);
Expand All @@ -54,14 +54,14 @@ test.beforeAll(async ({ pdRunner, welcomePage, page }) => {
await createKindCluster(page, CLUSTER_NAME, true, CLUSTER_CREATION_TIMEOUT);
});

test.afterAll(async ({ pdRunner, page }) => {
test.afterAll(async ({ runner, page }) => {
test.setTimeout(90000);
try {
await deleteContainer(page, CONTAINER_NAME);
await deleteImage(page, IMAGE_TO_PULL);
await deleteKindCluster(page, KIND_CONTAINER_NAME);
} finally {
await pdRunner.close();
await runner.close();
}
});

Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/extension-installation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ResourcesPage } from '../model/pages/resources-page';
import { SettingsBar } from '../model/pages/settings-bar';
import { WelcomePage } from '../model/pages/welcome-page';
import { NavigationBar } from '../model/workbench/navigation';
import { PodmanDesktopRunner } from '../runner/podman-desktop-runner';
import { Runner } from '../runner/podman-desktop-runner';

const DISABLED = 'DISABLED';
const ACTIVE = 'ACTIVE';
Expand All @@ -37,7 +37,7 @@ const OPENSHIFT_LOCAL = 'Red Hat Openshift Local';
const OPENSHIFT_SANDBOX = 'Red Hat OpenShift Sandbox';
const OPENSHIFT_CHECKER = 'Red Hat Openshift Checker';

let pdRunner: PodmanDesktopRunner;
let pdRunner: Runner;
let page: Page;

let extensionDashboardStatus: Locator | undefined;
Expand All @@ -50,8 +50,8 @@ let ociImageUrl: string;
let navigationBar: NavigationBar;

async function _startup(extensionName: string): Promise<void> {
pdRunner = await PodmanDesktopRunner.getInstance();
page = await pdRunner.start();
pdRunner = await Runner.getInstance();
page = pdRunner.getPage();
pdRunner.setVideoAndTraceName(`${extensionName}-installation-e2e`);

const welcomePage = new WelcomePage(page);
Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/image-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ const imageList = ['quay.io/podman/image1', 'quay.io/podman/image2'];
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

test.beforeAll(async ({ pdRunner, welcomePage, page }) => {
pdRunner.setVideoAndTraceName('pull-image-e2e');
test.beforeAll(async ({ runner, welcomePage, page }) => {
runner.setVideoAndTraceName('pull-image-e2e');

await welcomePage.handleWelcomePage(true);
await waitForPodmanMachineStartup(page);
});

test.afterAll(async ({ pdRunner }) => {
await pdRunner.close();
test.afterAll(async ({ runner }) => {
await runner.close();
});

test.describe.serial('Image workflow verification @smoke', () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/kind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ let kindResourceCard: ResourceConnectionCardPage;

const skipKindInstallation = process.env.SKIP_KIND_INSTALL ? process.env.SKIP_KIND_INSTALL : false;

test.beforeAll(async ({ pdRunner, page, welcomePage }) => {
pdRunner.setVideoAndTraceName('kind-e2e');
test.beforeAll(async ({ runner, page, welcomePage }) => {
runner.setVideoAndTraceName('kind-e2e');
await welcomePage.handleWelcomePage(true);
await waitForPodmanMachineStartup(page);
resourcesPage = new ResourcesPage(page);
kindResourceCard = new ResourceConnectionCardPage(page, RESOURCE_NAME);
});

test.afterAll(async ({ pdRunner }) => {
await pdRunner.close();
test.afterAll(async ({ runner }) => {
await runner.close();
});

test.describe.serial('Kind End-to-End Tests', () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/pod-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ test.skip(
'Tests suite should not run on Linux platform',
);

test.beforeAll(async ({ pdRunner, welcomePage, page, navigationBar }) => {
pdRunner.setVideoAndTraceName('pods-e2e');
test.beforeAll(async ({ runner, welcomePage, page, navigationBar }) => {
runner.setVideoAndTraceName('pods-e2e');
await welcomePage.handleWelcomePage(true);
await waitForPodmanMachineStartup(page);
// wait giving a time to podman desktop to load up
Expand All @@ -59,7 +59,7 @@ test.beforeAll(async ({ pdRunner, welcomePage, page, navigationBar }) => {
await deleteContainer(page, frontendContainer);
});

test.afterAll(async ({ page, pdRunner }) => {
test.afterAll(async ({ page, runner }) => {
test.setTimeout(120000);

try {
Expand All @@ -76,7 +76,7 @@ test.afterAll(async ({ page, pdRunner }) => {
await deleteImage(page, backendImage);
await deleteImage(page, frontendImage);
} finally {
await pdRunner.close();
await runner.close();
}
});

Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/src/specs/podman-extension-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ let dashboardPage: DashboardPage;
let settingsBar: SettingsBar;
let navigationBar: NavigationBar;

test.beforeAll(async ({ pdRunner, welcomePage, page }) => {
pdRunner.setVideoAndTraceName('podman-extensions-e2e');
test.beforeAll(async ({ runner, welcomePage, page }) => {
runner.setVideoAndTraceName('podman-extensions-e2e');
await welcomePage.handleWelcomePage(true);
navigationBar = new NavigationBar(page);
});

test.afterAll(async ({ pdRunner }) => {
test.afterAll(async ({ runner }) => {
test.setTimeout(120000);
await pdRunner.close();
await runner.close();
});

test.describe.serial('Verification of Podman extension @smoke', () => {
Expand Down
Loading

0 comments on commit 38937a9

Please sign in to comment.