1
1
/**********************************************************************
2
- * Copyright (C) 2024 Red Hat, Inc.
2
+ * Copyright (C) 2023 Red Hat, Inc.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -24,10 +24,13 @@ import { ResourcesPage } from './resources-page';
24
24
25
25
export class CreateMachinePage extends BasePage {
26
26
readonly heading : Locator ;
27
- readonly machineNameBox : Locator ;
27
+ readonly podmanMachineName : Locator ;
28
28
readonly podmanMachineConfiguration : Locator ;
29
29
readonly imagePathBox : Locator ;
30
30
readonly browseImagesButton : Locator ;
31
+ readonly podmanMachineCPUs : Locator ;
32
+ readonly podmanMachineMemory : Locator ;
33
+ readonly podmanMachineDiskSize : Locator ;
31
34
readonly rootPriviledgesCheckbox : Locator ;
32
35
readonly userModeNetworkingCheckbox : Locator ;
33
36
readonly startNowCheckbox : Locator ;
@@ -38,30 +41,42 @@ export class CreateMachinePage extends BasePage {
38
41
super ( page ) ;
39
42
this . heading = this . page . getByRole ( 'heading' , { name : 'Create Podman Machine' } ) ;
40
43
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' } ) ;
43
45
this . imagePathBox = this . page . getByRole ( 'textbox' , { name : 'Image Path (Optional) ' } ) ;
44
46
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' ,
50
55
} ) ;
51
- this . startNowCheckbox = this . page . getByRole ( 'checkbox' , { name : 'Start the machine now' } ) ;
56
+ this . startNowCheckbox = this . podmanMachineConfiguration . getByRole ( 'checkbox' , { name : 'Start the machine now' } ) ;
52
57
this . closeButton = this . page . getByRole ( 'button' , { name : 'Close' } ) ;
53
58
this . createMachineButton = this . page . getByRole ( 'button' , { name : 'Create' } ) ;
54
59
}
55
60
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 > {
57
67
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
+ }
59
73
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 ) ;
65
80
}
66
81
67
82
await this . createMachineButton . click ( ) ;
@@ -75,4 +90,27 @@ export class CreateMachinePage extends BasePage {
75
90
76
91
return new ResourcesPage ( this . page ) ;
77
92
}
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
+ }
78
116
}
0 commit comments