1
1
import { Locator } from "@playwright/test" ;
2
2
import BasePage from "@/e2e/infra/ui/basePage" ;
3
- import { waitForElementToBeVisible , waitForTimeOut } from '../../infra/utils'
3
+ import { interactWhenVisible , waitForTimeOut } from '../../infra/utils'
4
4
5
5
export default class SettingsUsersPage extends BasePage {
6
6
@@ -84,9 +84,13 @@ export default class SettingsUsersPage extends BasePage {
84
84
return this . page . locator ( "//table//tbody//tr" ) ;
85
85
}
86
86
87
+ private get undoBtnInNotification ( ) : Locator {
88
+ return this . page . locator ( '//ol//li//button[contains(text(), "Undo")]' ) ;
89
+ }
90
+
87
91
async navigateToUserTab ( ) : Promise < void > {
88
92
await this . waitForPageIdle ( ) ;
89
- await this . usersTabBtn . click ( ) ;
93
+ await this . clickUserTab ( ) ;
90
94
}
91
95
92
96
async verifyUserExists ( selectedUser : string ) : Promise < boolean > {
@@ -95,46 +99,76 @@ export default class SettingsUsersPage extends BasePage {
95
99
return isVisible ;
96
100
}
97
101
102
+ async clickUserTab ( ) : Promise < void > {
103
+ await interactWhenVisible ( this . usersTabBtn , el => el . click ( ) , "user tab button" ) ;
104
+ }
105
+
98
106
async clickOnAddUserBtn ( ) : Promise < void > {
99
- const isVisible = await waitForElementToBeVisible ( this . addUserButton ) ;
100
- if ( ! isVisible ) throw new Error ( "add user button is not visible!" ) ;
101
- await this . addUserButton . click ( ) ;
107
+ await interactWhenVisible ( this . addUserButton , el => el . click ( ) , "add user button" ) ;
102
108
}
103
109
104
110
async fillUserNameField ( userName : string ) : Promise < void > {
105
- const isVisible = await waitForElementToBeVisible ( this . userNameField ) ;
106
- if ( ! isVisible ) throw new Error ( "user name input is not visible!" ) ;
107
- await this . userNameField . fill ( userName ) ;
111
+ await interactWhenVisible ( this . userNameField , el => el . fill ( userName ) , "username input" ) ;
108
112
}
109
113
110
114
async fillPasswordField ( password : string ) : Promise < void > {
111
- const isVisible = await waitForElementToBeVisible ( this . passwordField ) ;
112
- if ( ! isVisible ) throw new Error ( "password input is not visible!" ) ;
113
- await this . passwordField . fill ( password ) ;
115
+ await interactWhenVisible ( this . passwordField , el => el . fill ( password ) , "password input" ) ;
114
116
}
115
117
116
118
async fillConfirmPasswordField ( confirmPassword : string ) : Promise < void > {
117
- const isVisible = await waitForElementToBeVisible ( this . passwordField ) ;
118
- if ( ! isVisible ) throw new Error ( "confirm password input is not visible!" ) ;
119
- await this . confirmPasswordField . fill ( confirmPassword ) ;
119
+ await interactWhenVisible ( this . confirmPasswordField , el => el . fill ( confirmPassword ) , "confirm password input" ) ;
120
120
}
121
121
122
122
async clickOnSelectRoleBtnInAddUser ( ) : Promise < void > {
123
- const isVisible = await waitForElementToBeVisible ( this . selectRoleBtnInAddUser ) ;
124
- if ( ! isVisible ) throw new Error ( "select role button is not visible!" ) ;
125
- await this . selectRoleBtnInAddUser . click ( ) ;
123
+ await interactWhenVisible ( this . selectRoleBtnInAddUser , el => el . click ( ) , "select role button" ) ;
126
124
}
127
125
128
126
async clickOnSelectUserRole ( role : string ) : Promise < void > {
129
- const isVisible = await waitForElementToBeVisible ( this . selectRoleBtnInAddUser ) ;
130
- if ( ! isVisible ) throw new Error ( "select role button is not visible!" ) ;
131
- await this . selectUserRole ( role ) . click ( ) ;
127
+ await interactWhenVisible ( this . selectUserRole ( role ) , el => el . click ( ) , "select role button" ) ;
132
128
}
133
129
134
130
async clickOnSubmitUserAddition ( ) : Promise < void > {
135
- const isVisible = await waitForElementToBeVisible ( this . submitUserAddition ) ;
136
- if ( ! isVisible ) throw new Error ( "submit user addition button is not visible!" ) ;
137
- await this . submitUserAddition . click ( ) ;
131
+ await interactWhenVisible ( this . submitUserAddition , el => el . click ( ) , "submit user addition button" ) ;
132
+ }
133
+
134
+ async clickUndoBtnInNotification ( ) : Promise < void > {
135
+ await interactWhenVisible ( this . undoBtnInNotification , el => el . click ( ) , "undo button in notification" ) ;
136
+ }
137
+
138
+ async hoverUserRow ( selectedUser : string ) : Promise < void > {
139
+ await interactWhenVisible ( this . userRow ( selectedUser ) , el => el . hover ( ) , "hover on user row" ) ;
140
+ }
141
+
142
+ async clickUserSelectRoleEditBtn ( selectedUser : string ) : Promise < void > {
143
+ await interactWhenVisible ( this . userSelectRoleEditBtn ( selectedUser ) , el => el . click ( ) , "user select role edit button" ) ;
144
+ }
145
+
146
+ async clickUserSelectRoleBtn ( selectedUser : string ) : Promise < void > {
147
+ await interactWhenVisible ( this . userSelectRoleBtn ( selectedUser ) , el => el . click ( ) , "user select first role button" ) ;
148
+ }
149
+
150
+ async clickUserCheckboxBtn ( selectedUser : string ) : Promise < void > {
151
+ await interactWhenVisible ( this . userCheckboxBtn ( selectedUser ) , el => el . click ( ) , "user checkbox button" ) ;
152
+ }
153
+
154
+ async clickDeleteUsersBtn ( ) : Promise < void > {
155
+ await interactWhenVisible ( this . deleteUsersBtn , el => el . click ( ) , "delete user button" ) ;
156
+ }
157
+
158
+ async clickConfirmUserDeleteMsg ( ) : Promise < void > {
159
+ await interactWhenVisible ( this . confirmUserDeleteMsg , el => el . click ( ) , "confirm user delete button" ) ;
160
+ }
161
+
162
+ async clickOnConfirmModifyingUserRole ( ) : Promise < void > {
163
+ await interactWhenVisible ( this . confirmModifyingUserRole , el => el . click ( ) , "confirm modify user role button" ) ;
164
+ }
165
+
166
+ async clickSearchBtn ( ) : Promise < void > {
167
+ await interactWhenVisible ( this . searchBtn , el => el . click ( ) , "search button" ) ;
168
+ }
169
+
170
+ async fillSearchInput ( input : string ) : Promise < void > {
171
+ await interactWhenVisible ( this . searchInput , el => el . fill ( input ) , "search input button" ) ;
138
172
}
139
173
140
174
async addUser ( userDetails : { [ key : string ] : string } ) : Promise < void > {
@@ -153,40 +187,40 @@ export default class SettingsUsersPage extends BasePage {
153
187
154
188
async getUserRole ( selectedUser : string ) : Promise < string | null > {
155
189
await this . waitForPageIdle ( ) ;
190
+ await this . page . waitForTimeout ( 500 ) ;
156
191
const role = await this . userRoleContent ( selectedUser ) . textContent ( ) ;
157
192
return role ;
158
193
}
159
194
160
195
async modifyUserRole ( selectedUser : string , role : string ) : Promise < void > {
161
196
await this . waitForPageIdle ( ) ;
162
- await this . userRow ( selectedUser ) . hover ( ) ;
163
- await this . userSelectRoleEditBtn ( selectedUser ) . waitFor ( { state : "visible" } ) ;
164
- await this . userSelectRoleEditBtn ( selectedUser ) . click ( ) ;
165
- await this . userSelectRoleBtn ( selectedUser ) . click ( ) ;
166
- await this . selectUserRole ( role ) . click ( ) ;
197
+ await this . hoverUserRow ( selectedUser ) ;
198
+ await this . clickUserSelectRoleEditBtn ( selectedUser ) ;
199
+ await this . clickUserSelectRoleBtn ( selectedUser ) ;
200
+ await this . clickOnSelectUserRole ( role ) ;
167
201
await this . clickOnConfirmModifyingUserRole ( ) ;
168
- await waitForTimeOut ( this . page , 1500 )
202
+ await waitForTimeOut ( this . page , 1500 ) ;
169
203
}
170
204
171
205
async deleteTwoUsers ( selectedUser1 : string , selectedUser2 : string ) : Promise < void > {
172
206
await this . waitForPageIdle ( ) ;
173
- await this . userCheckboxBtn ( selectedUser1 ) . click ( )
174
- await this . userCheckboxBtn ( selectedUser2 ) . click ( )
175
- await this . deleteUsersBtn . click ( )
176
- await this . confirmUserDeleteMsg . click ( )
207
+ await this . clickUserCheckboxBtn ( selectedUser1 ) ;
208
+ await this . clickUserCheckboxBtn ( selectedUser2 ) ;
209
+ await this . clickDeleteUsersBtn ( ) ;
210
+ await this . clickConfirmUserDeleteMsg ( ) ;
177
211
await waitForTimeOut ( this . page , 1500 )
178
212
}
179
213
180
214
async removeUser ( selectedUser : string ) : Promise < void > {
181
215
await this . waitForPageIdle ( ) ;
182
- await this . userCheckboxBtn ( selectedUser ) . click ( ) ;
183
- await this . deleteUsersBtn . click ( ) ;
184
- await this . confirmUserDeleteMsg . click ( ) ;
216
+ await this . clickUserCheckboxBtn ( selectedUser ) ;
217
+ await this . clickDeleteUsersBtn ( ) ;
218
+ await this . clickConfirmUserDeleteMsg ( ) ;
185
219
}
186
220
187
221
async searchForElement ( element : string ) : Promise < void > {
188
- await this . searchBtn . click ( ) ;
189
- await this . searchInput . fill ( element ) ;
222
+ await this . clickSearchBtn ( ) ;
223
+ await this . fillSearchInput ( element ) ;
190
224
await this . page . keyboard . press ( 'Enter' ) ;
191
225
}
192
226
@@ -195,8 +229,4 @@ export default class SettingsUsersPage extends BasePage {
195
229
const count = await this . tableRoles . count ( ) ;
196
230
return count ;
197
231
}
198
-
199
- async clickOnConfirmModifyingUserRole ( ) : Promise < void > {
200
- await this . confirmModifyingUserRole . click ( ) ;
201
- }
202
232
}
0 commit comments