forked from podman-desktop/podman-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine-creation-form.ts
82 lines (74 loc) · 3.62 KB
/
machine-creation-form.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**********************************************************************
* Copyright (C) 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
***********************************************************************/
import type { Locator, Page } from '@playwright/test';
import { expect as playExpect } from '@playwright/test';
import { BasePage } from '../base-page';
export class MachineCreationForm extends BasePage {
readonly podmanMachineConfiguration: Locator;
readonly podmanMachineName: Locator;
readonly imagePathBox: Locator;
readonly browseImagesButton: Locator;
readonly podmanMachineCPUs: Locator;
readonly podmanMachineMemory: Locator;
readonly podmanMachineDiskSize: Locator;
readonly rootPriviledgesCheckbox: Locator;
readonly userModeNetworkingCheckbox: Locator;
readonly startNowCheckbox: Locator;
readonly createMachineButton: Locator;
constructor(page: Page) {
super(page);
this.podmanMachineConfiguration = this.page.getByRole('form', { name: 'Properties Information' });
this.podmanMachineName = this.podmanMachineConfiguration.getByRole('textbox', { name: 'Name' });
this.imagePathBox = this.podmanMachineConfiguration.getByRole('textbox', { name: 'Image Path (Optional) ' });
this.browseImagesButton = this.podmanMachineConfiguration.getByRole('button', {
name: 'button-Image Path (Optional)',
});
this.podmanMachineCPUs = this.podmanMachineConfiguration.getByRole('slider', { name: 'CPU(s)' });
this.podmanMachineMemory = this.podmanMachineConfiguration.getByRole('slider', { name: 'Memory' });
this.podmanMachineDiskSize = this.podmanMachineConfiguration.getByRole('slider', { name: 'Disk size' });
this.rootPriviledgesCheckbox = this.podmanMachineConfiguration.getByRole('checkbox', {
name: 'Machine with root privileges',
});
this.userModeNetworkingCheckbox = this.podmanMachineConfiguration.getByRole('checkbox', {
name: 'User mode networking',
});
this.startNowCheckbox = this.podmanMachineConfiguration.getByRole('checkbox', { name: 'Start the machine now' });
this.createMachineButton = this.podmanMachineConfiguration.getByRole('button', { name: 'Create' });
}
async setupAndCreateMachine(
machineName: string,
isRootful: boolean,
enableUserNet: boolean,
startNow: boolean,
): Promise<void> {
await playExpect(this.podmanMachineConfiguration).toBeVisible({ timeout: 10_000 });
await this.podmanMachineName.clear();
await this.podmanMachineName.fill(machineName);
await this.ensureCheckboxState(isRootful, this.rootPriviledgesCheckbox);
await this.ensureCheckboxState(enableUserNet, this.userModeNetworkingCheckbox);
await this.ensureCheckboxState(startNow, this.startNowCheckbox);
await playExpect(this.createMachineButton).toBeEnabled();
await this.createMachineButton.click();
}
async ensureCheckboxState(desiredState: boolean, checkbox: Locator): Promise<void> {
if (desiredState !== (await checkbox.isChecked())) {
await checkbox.locator('..').click();
playExpect(await checkbox.isChecked()).toBe(desiredState);
}
}
}