Skip to content

Commit 51c891d

Browse files
committed
chore(tests): create rootless fixed
Signed-off-by: Tamara Babalova <[email protected]>
1 parent da2c3b2 commit 51c891d

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

tests/playwright/src/model/pages/create-machine-page.ts

+55-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (C) 2024 Red Hat, Inc.
2+
* Copyright (C) 2023 Red Hat, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,10 +24,13 @@ import { ResourcesPage } from './resources-page';
2424

2525
export class CreateMachinePage extends BasePage {
2626
readonly heading: Locator;
27-
readonly machineNameBox: Locator;
27+
readonly podmanMachineName: Locator;
2828
readonly podmanMachineConfiguration: Locator;
2929
readonly imagePathBox: Locator;
3030
readonly browseImagesButton: Locator;
31+
readonly podmanMachineCPUs: Locator;
32+
readonly podmanMachineMemory: Locator;
33+
readonly podmanMachineDiskSize: Locator;
3134
readonly rootPriviledgesCheckbox: Locator;
3235
readonly userModeNetworkingCheckbox: Locator;
3336
readonly startNowCheckbox: Locator;
@@ -38,30 +41,42 @@ export class CreateMachinePage extends BasePage {
3841
super(page);
3942
this.heading = this.page.getByRole('heading', { name: 'Create Podman Machine' });
4043
this.podmanMachineConfiguration = this.page.getByRole('form', { name: 'Properties Information' });
41-
42-
this.machineNameBox = this.podmanMachineConfiguration.getByRole('textbox', { name: 'Name' });
44+
this.podmanMachineName = this.podmanMachineConfiguration.getByRole('textbox', { name: 'Name' });
4345
this.imagePathBox = this.page.getByRole('textbox', { name: 'Image Path (Optional) ' });
4446
this.browseImagesButton = this.page.getByRole('button', { name: 'button-Image Path (Optional)' });
45-
this.rootPriviledgesCheckbox = this.podmanMachineConfiguration
46-
.getByRole('checkbox', { name: 'Machine with root privileges' })
47-
.locator('..');
48-
this.userModeNetworkingCheckbox = this.page.getByRole('checkbox', {
49-
name: 'User mode networking (traffic relayed by a user process). See [documentation](https://docs.podman.io/en/latest/markdown/podman-machine-init.1.html#user-mode-networking).',
47+
this.podmanMachineCPUs = this.podmanMachineConfiguration.getByRole('slider', { name: 'CPU(s)' });
48+
this.podmanMachineMemory = this.podmanMachineConfiguration.getByRole('slider', { name: 'Memory' });
49+
this.podmanMachineDiskSize = this.podmanMachineConfiguration.getByRole('slider', { name: 'Disk size' });
50+
this.rootPriviledgesCheckbox = this.podmanMachineConfiguration.getByRole('checkbox', {
51+
name: 'Machine with root privileges',
52+
});
53+
this.userModeNetworkingCheckbox = this.podmanMachineConfiguration.getByRole('checkbox', {
54+
name: 'User mode networking',
5055
});
51-
this.startNowCheckbox = this.page.getByRole('checkbox', { name: 'Start the machine now' });
56+
this.startNowCheckbox = this.podmanMachineConfiguration.getByRole('checkbox', { name: 'Start the machine now' });
5257
this.closeButton = this.page.getByRole('button', { name: 'Close' });
5358
this.createMachineButton = this.page.getByRole('button', { name: 'Create' });
5459
}
5560

56-
async createMachine(machineName: string, isRootless: boolean): Promise<ResourcesPage> {
61+
async createMachine(
62+
machineName: string,
63+
isRootful: boolean = true,
64+
enableUserNet: boolean = false,
65+
startNow: boolean = true,
66+
): Promise<ResourcesPage> {
5767
await playExpect(this.podmanMachineConfiguration).toBeVisible();
58-
await this.machineNameBox.fill(machineName);
68+
await this.podmanMachineName.fill(machineName);
69+
70+
if (isRootful !== (await this.isEnabled(this.rootPriviledgesCheckbox))) {
71+
await this.switchCheckbox(this.rootPriviledgesCheckbox);
72+
}
5973

60-
if (!isRootless) {
61-
await playExpect(this.rootPriviledgesCheckbox).toBeVisible();
62-
const upperElement = this.rootPriviledgesCheckbox.locator('..');
63-
const clickableCheckbox = upperElement.getByText('Enable');
64-
await clickableCheckbox.click();
74+
if (enableUserNet !== (await this.isEnabled(this.userModeNetworkingCheckbox))) {
75+
await this.switchCheckbox(this.userModeNetworkingCheckbox);
76+
}
77+
78+
if (startNow !== (await this.isEnabled(this.startNowCheckbox))) {
79+
await this.switchCheckbox(this.startNowCheckbox);
6580
}
6681

6782
await this.createMachineButton.click();
@@ -75,4 +90,27 @@ export class CreateMachinePage extends BasePage {
7590

7691
return new ResourcesPage(this.page);
7792
}
93+
94+
async isEnabled(checkbox: Locator): Promise<boolean> {
95+
await playExpect(checkbox).toBeVisible();
96+
const upperElement = checkbox.locator('..').locator('..');
97+
const clickableCheckbox = upperElement.getByText('Enabled');
98+
return await clickableCheckbox.isVisible();
99+
}
100+
101+
async switchCheckbox(checkbox: Locator): Promise<void> {
102+
await playExpect(checkbox).toBeVisible();
103+
const upperElement = checkbox.locator('..').locator('..');
104+
105+
const wasEnabled = await this.isEnabled(checkbox);
106+
let checkText;
107+
if (wasEnabled) {
108+
checkText = 'Enabled';
109+
} else {
110+
checkText = 'Disabled';
111+
}
112+
113+
const clickableCheckbox = upperElement.getByText(checkText);
114+
await clickableCheckbox.click();
115+
}
78116
}

tests/playwright/src/specs/podman-machine-rootless.spec.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import { deletePodmanMachine } from '../utility/operations';
3333
let pdRunner: PodmanDesktopRunner;
3434
let page: Page;
3535
let navBar: NavigationBar;
36-
const PODMAN_MACHINE_NAME: string = 'Podman Machine Rootless';
36+
const PODMAN_MACHINE_NAME: string = 'podman-machine-rootless';
37+
const MACHINE_VISIBLE_NAME: string = 'Podman Machine rootless';
3738

3839
beforeAll(async () => {
3940
pdRunner = new PodmanDesktopRunner();
@@ -65,12 +66,10 @@ describe.skipIf(os.platform() === 'linux')('Rootless Podman machine Verification
6566
await createMachineButton.click();
6667

6768
const createMachinePage = new CreateMachinePage(page);
68-
await createMachinePage.createMachine(PODMAN_MACHINE_NAME, false);
69+
await createMachinePage.createMachine(PODMAN_MACHINE_NAME, false, false, true);
6970

70-
const machineBox = new ResourcesPodmanConnections(page, PODMAN_MACHINE_NAME);
71-
const connectionStatusLabel = await machineBox.machineConnectionStatus
72-
.getByLabel('Connection Status Label')
73-
.textContent();
71+
const machineBox = new ResourcesPodmanConnections(page, MACHINE_VISIBLE_NAME);
72+
const connectionStatusLabel = await machineBox.machineConnectionStatus.textContent();
7473
playExpect(connectionStatusLabel === 'RUNNING').toBeTruthy();
7574
}, 150000);
7675
});

0 commit comments

Comments
 (0)