Skip to content

Commit 4ff9e36

Browse files
committed
add tests for (#878), update pom
1 parent db495bf commit 4ff9e36

File tree

4 files changed

+123
-83
lines changed

4 files changed

+123
-83
lines changed

e2e/logic/POM/settingsConfigPage.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Locator } from "@playwright/test";
22
import BasePage from "@/e2e/infra/ui/basePage";
3-
import { waitForElementToBeVisible } from "@/e2e/infra/utils";
3+
import { interactWhenVisible } from "@/e2e/infra/utils";
44

55
export default class SettingsConfigPage extends BasePage {
66

@@ -53,67 +53,60 @@ export default class SettingsConfigPage extends BasePage {
5353
}
5454

5555
async hoverOnRoleContentValue(role: string): Promise<void> {
56-
const isVisible = await waitForElementToBeVisible(this.roleContentValue(role));
57-
if (!isVisible) throw new Error("role content value is not visible!");
58-
await this.roleContentValue(role).hover();
56+
await interactWhenVisible(this.roleContentValue(role), el => el.hover(), "role content value");
5957
}
60-
58+
6159
async clickEditRoleButton(role: string): Promise<void> {
62-
const isVisible = await waitForElementToBeVisible(this.EditRoleButton(role));
63-
if (!isVisible) throw new Error("edit role button is not visible!");
64-
await this.EditRoleButton(role).click();
60+
await interactWhenVisible(this.EditRoleButton(role), el => el.click(), "edit role button");
6561
}
66-
62+
6763
async fillRoleValueInput(role: string, input: string): Promise<void> {
68-
const isVisible = await waitForElementToBeVisible(this.roleValueInput(role));
69-
if (!isVisible) throw new Error("role value input is not visible!");
70-
await this.roleValueInput(role).fill(input);
64+
await interactWhenVisible(this.roleValueInput(role), el => el.fill(input), "role value input");
7165
}
72-
66+
7367
async clickConfirmValueInputBtn(role: string): Promise<void> {
74-
const isVisible = await waitForElementToBeVisible(this.confirmValueInputBtn(role));
75-
if (!isVisible) throw new Error("confirm value input button is not visible!");
76-
await this.confirmValueInputBtn(role).click();
68+
await interactWhenVisible(this.confirmValueInputBtn(role), el => el.click(), "confirm value input button");
7769
}
78-
70+
7971
async getRoleContentValue(role: string): Promise<string | null> {
80-
const isVisible = await waitForElementToBeVisible(this.roleContentValue(role));
81-
if (!isVisible) throw new Error("role content value is not visible!");
82-
const value = await this.roleContentValue(role).textContent();
83-
return value
72+
return await interactWhenVisible(this.roleContentValue(role), el => el.textContent(), "role content value");
8473
}
85-
74+
8675
async clickOnUndoBtnInToastMsg(): Promise<void> {
87-
const isVisible = await waitForElementToBeVisible(this.undoBtnInToastMsg);
88-
if (!isVisible) throw new Error("undo button in toast is not visible!");
89-
await this.undoBtnInToastMsg.click();
76+
await interactWhenVisible(this.undoBtnInToastMsg, el => el.click(), "undo button in toast");
77+
}
78+
79+
async clickSearchBtn(): Promise<void> {
80+
await interactWhenVisible(this.searchBtn, el => el.click(), "search button");
81+
}
82+
83+
async fillSearchInput(element: string): Promise<void> {
84+
await interactWhenVisible(this.searchInput, el => el.fill(element), "search button");
85+
}
86+
87+
async clickOnToastCloseBtn(): Promise<void> {
88+
await interactWhenVisible(this.toastCloseBtn, el => el.click(), "toast close button");
9089
}
9190

9291
async isUndoBtnInToastMsg(): Promise<void> {
9392
await this.page.waitForTimeout(500);
9493
await this.undoBtnInToastMsg.isVisible();
9594
}
9695

97-
async modifyRoleValue(role: string, input: string): Promise<string | null> {
96+
async modifyRoleValue(role: string, input: string): Promise<void> {
9897
await this.hoverOnRoleContentValue(role);
9998
await this.clickEditRoleButton(role);
100-
await this.roleValueInput(role).fill(input);
99+
await this.fillRoleValueInput(role, input);
101100
await this.clickConfirmValueInputBtn(role);
102-
const value = await this.getRoleContentValue(role);
103-
return value
104-
}
105-
106-
async clickOnToastCloseBtn(): Promise<void> {
107-
await this.toastCloseBtn.click();
108101
}
109102

110103
async scrollToBottomInTable(): Promise<void> {
111104
await this.tableContent.evaluate((el) => el.scrollTo(0, el.scrollHeight));
112105
}
113106

114107
async searchForElement(element: string): Promise<void> {
115-
await this.searchBtn.click();
116-
await this.searchInput.fill(element);
108+
await this.clickSearchBtn();
109+
await this.fillSearchInput(element);
117110
await this.page.keyboard.press('Enter');
118111
}
119112

@@ -127,5 +120,4 @@ export default class SettingsConfigPage extends BasePage {
127120
await this.page.reload({ waitUntil: 'networkidle' });
128121
await this.navigateToDBConfigurationTab();
129122
}
130-
131123
}

e2e/logic/POM/settingsUsersPage.ts

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Locator } from "@playwright/test";
22
import BasePage from "@/e2e/infra/ui/basePage";
3-
import { waitForElementToBeVisible, waitForTimeOut } from '../../infra/utils'
3+
import { interactWhenVisible, waitForTimeOut } from '../../infra/utils'
44

55
export default class SettingsUsersPage extends BasePage {
66

@@ -84,9 +84,13 @@ export default class SettingsUsersPage extends BasePage {
8484
return this.page.locator("//table//tbody//tr");
8585
}
8686

87+
private get undoBtnInNotification(): Locator {
88+
return this.page.locator('//ol//li//button[contains(text(), "Undo")]');
89+
}
90+
8791
async navigateToUserTab(): Promise<void> {
8892
await this.waitForPageIdle();
89-
await this.usersTabBtn.click();
93+
await this.clickUserTab();
9094
}
9195

9296
async verifyUserExists(selectedUser: string): Promise<boolean> {
@@ -95,46 +99,76 @@ export default class SettingsUsersPage extends BasePage {
9599
return isVisible;
96100
}
97101

102+
async clickUserTab(): Promise<void>{
103+
await interactWhenVisible(this.usersTabBtn, el => el.click(), "user tab button");
104+
}
105+
98106
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");
102108
}
103109

104110
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");
108112
}
109113

110114
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");
114116
}
115117

116118
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");
120120
}
121121

122122
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");
126124
}
127125

128126
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");
132128
}
133129

134130
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");
138172
}
139173

140174
async addUser(userDetails: { [key: string]: string }): Promise<void> {
@@ -153,40 +187,40 @@ export default class SettingsUsersPage extends BasePage {
153187

154188
async getUserRole(selectedUser: string): Promise<string | null> {
155189
await this.waitForPageIdle();
190+
await this.page.waitForTimeout(500);
156191
const role = await this.userRoleContent(selectedUser).textContent();
157192
return role;
158193
}
159194

160195
async modifyUserRole(selectedUser: string, role: string): Promise<void> {
161196
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);
167201
await this.clickOnConfirmModifyingUserRole();
168-
await waitForTimeOut(this.page, 1500)
202+
await waitForTimeOut(this.page, 1500);
169203
}
170204

171205
async deleteTwoUsers(selectedUser1: string, selectedUser2: string): Promise<void> {
172206
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();
177211
await waitForTimeOut(this.page, 1500)
178212
}
179213

180214
async removeUser(selectedUser: string): Promise<void> {
181215
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();
185219
}
186220

187221
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);
190224
await this.page.keyboard.press('Enter');
191225
}
192226

@@ -195,8 +229,4 @@ export default class SettingsUsersPage extends BasePage {
195229
const count = await this.tableRoles.count();
196230
return count;
197231
}
198-
199-
async clickOnConfirmModifyingUserRole(): Promise<void>{
200-
await this.confirmModifyingUserRole.click();
201-
}
202232
}

e2e/tests/settingsConfig.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,13 @@ test.describe('@config Settings config tests', () => {
264264
});
265265
})
266266

267+
test(`@admin Validate undo after modifying a config role`, async () => {
268+
const settingsConfigPage = await browser.createNewPage(SettingsConfigPage, urls.settingsUrl)
269+
await settingsConfigPage.navigateToDBConfigurationTab();
270+
await settingsConfigPage.modifyRoleValue(roles.maxInfoQueries, "999")
271+
await settingsConfigPage.clickOnUndoBtnInToastMsg();
272+
const value = String((await apiCall.getSettingsRoleValue(roles.maxInfoQueries)).config[1]);
273+
expect(value).toBe("1000");
274+
});
275+
267276
})

e2e/tests/settingsUsers.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { getRandomString } from "../infra/utils";
88

99
test.describe('@Config Settings users tests', () => {
1010
let browser: BrowserWrapper;
11+
let apiCall: ApiCalls;
1112

1213
test.beforeEach(async () => {
1314
browser = new BrowserWrapper();
15+
apiCall = new ApiCalls();
1416
})
1517

1618
test.afterEach(async () => {
@@ -94,7 +96,6 @@ test.describe('@Config Settings users tests', () => {
9496
})
9597

9698
test("@admin API Test: Add user via API -> Validated user existing via UI -> Delete user via API.", async () => {
97-
const apiCall = new ApiCalls();
9899
const username = getRandomString('user');
99100
await apiCall.createUsers({ username, password: user.password, role: user.ReadOnly });
100101
const settingsUsersPage = await browser.createNewPage(SettingsUsersPage, urls.settingsUrl);
@@ -105,7 +106,6 @@ test.describe('@Config Settings users tests', () => {
105106
})
106107

107108
test(`@admin API Test: without passing a username, Attempt to add a user via api and validate the user was not added via ui`, async () => {
108-
const apiCall = new ApiCalls();
109109
const username = '';
110110
await apiCall.createUsers({ username, password: user.password, role: user.ReadOnly });
111111
const settingsUsersPage = await browser.createNewPage(SettingsUsersPage, urls.settingsUrl);
@@ -115,7 +115,6 @@ test.describe('@Config Settings users tests', () => {
115115
});
116116

117117
test(`@admin API Test: without passing a role, Attempt to add a user via api and validate the user was not added via ui`, async () => {
118-
const apiCall = new ApiCalls();
119118
const username = getRandomString('user');
120119
await apiCall.createUsers({ username, password: user.password, role: '' });
121120
const settingsUsersPage = await browser.createNewPage(SettingsUsersPage, urls.settingsUrl);
@@ -125,7 +124,6 @@ test.describe('@Config Settings users tests', () => {
125124
});
126125

127126
test(`@admin API Test: without passing a password, Attempt to add a user via api and validate the user was not added via ui`, async () => {
128-
const apiCall = new ApiCalls();
129127
const username = getRandomString('user');
130128
await apiCall.createUsers({ username, password: '', role: user.ReadOnly });
131129
const settingsUsersPage = await browser.createNewPage(SettingsUsersPage, urls.settingsUrl);
@@ -135,7 +133,6 @@ test.describe('@Config Settings users tests', () => {
135133
});
136134

137135
test(`@admin Validate user search filters table results`, async () => {
138-
const apiCall = new ApiCalls()
139136
const username = getRandomString('user');
140137
await apiCall.createUsers({ username, password: user.password, role: user.ReadOnly })
141138
const settingsUsersPage = await browser.createNewPage(SettingsUsersPage, urls.settingsUrl)
@@ -145,4 +142,16 @@ test.describe('@Config Settings users tests', () => {
145142
await apiCall.deleteUsers({ users: [{ username }] })
146143
});
147144

145+
test("@admin Validate undo after modifying a user role", async () => {
146+
const username = getRandomString('user');
147+
await apiCall.createUsers({ username, password: user.password, role: user.ReadOnly });
148+
const settingsUsersPage = await browser.createNewPage(SettingsUsersPage, urls.settingsUrl);
149+
await settingsUsersPage.navigateToUserTab();
150+
await settingsUsersPage.modifyUserRole(username, user.ReadWrite);
151+
await settingsUsersPage.clickUndoBtnInNotification();
152+
const users = await apiCall.getUsers();
153+
const matchedUser = users.result.find(u => u.username === username)
154+
expect(matchedUser?.role).toBe("Read-Only");
155+
await apiCall.deleteUsers({ users: [{ username }] });
156+
})
148157
})

0 commit comments

Comments
 (0)