Skip to content

Commit d984347

Browse files
Fix pre-existing test bugs causing CI failures in auth and PIM tests
Co-authored-by: bg-playground <259109604+bg-playground@users.noreply.github.com>
1 parent b55e1e8 commit d984347

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

automated-testing/pages/LoginPage.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ export class LoginPage {
1717
await this.usernameInput.fill(username);
1818
await this.passwordInput.fill(password);
1919
await this.loginButton.click();
20-
21-
// Wait for dashboard to be fully loaded - single, reliable wait
20+
}
21+
22+
async loginAndWaitForDashboard(username, password) {
23+
await this.login(username, password);
2224
await this.page.waitForURL(/.*dashboard/, { timeout: 90000 });
2325
await this.page.getByRole('heading', { name: 'Dashboard' }).waitFor({ state: 'visible', timeout: 90000 });
2426
}

automated-testing/tests/ui/admin.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test.describe('Admin Module Tests', () => {
1515

1616
// Login before each test
1717
await loginPage.goto();
18-
await loginPage.login('Admin', 'admin123');
18+
await loginPage.loginAndWaitForDashboard('Admin', 'admin123');
1919
await expect(page).toHaveURL(/.*dashboard/);
2020
await dashboardPage.navigateToAdmin();
2121
});

automated-testing/tests/ui/auth.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test.describe('Authentication Tests', () => {
1414

1515
test('TC-AUTH-001: Valid Login', async ({ page }) => {
1616
await test.step('Enter valid credentials and login', async () => {
17-
await loginPage.login('Admin', 'admin123');
17+
await loginPage.loginAndWaitForDashboard('Admin', 'admin123');
1818
});
1919

2020
await test.step('Verify dashboard is displayed', async () => {
@@ -27,6 +27,7 @@ test.describe('Authentication Tests', () => {
2727
test('TC-AUTH-002: Invalid Username', async ({ page }) => {
2828
await test.step('Enter invalid username', async () => {
2929
await loginPage.login('InvalidUser', 'admin123');
30+
await loginPage.errorMessage.waitFor({ state: 'visible', timeout: 10000 });
3031
});
3132

3233
await test.step('Verify error message is displayed', async () => {
@@ -38,6 +39,7 @@ test.describe('Authentication Tests', () => {
3839
test('TC-AUTH-003: Invalid Password', async ({ page }) => {
3940
await test.step('Enter invalid password', async () => {
4041
await loginPage.login('Admin', 'WrongPassword');
42+
await loginPage.errorMessage.waitFor({ state: 'visible', timeout: 10000 });
4143
});
4244

4345
await test.step('Verify error message is displayed', async () => {
@@ -70,7 +72,7 @@ test.describe('Authentication Tests', () => {
7072

7173
test('TC-AUTH-006: Logout Functionality', async ({ page }) => {
7274
await test.step('Login successfully', async () => {
73-
await loginPage.login('Admin', 'admin123');
75+
await loginPage.loginAndWaitForDashboard('Admin', 'admin123');
7476
await expect(page).toHaveURL(/.*dashboard/);
7577
});
7678

@@ -88,6 +90,7 @@ test.describe('Authentication Tests', () => {
8890
test('TC-AUTH-008: SQL Injection Prevention', async ({ page }) => {
8991
await test.step('Attempt SQL injection in username', async () => {
9092
await loginPage.login("Admin' OR '1'='1", 'anything');
93+
await loginPage.errorMessage.waitFor({ state: 'visible', timeout: 10000 });
9194
});
9295

9396
await test.step('Verify login fails securely', async () => {
@@ -99,6 +102,7 @@ test.describe('Authentication Tests', () => {
99102
test('TC-AUTH-009: XSS Prevention', async ({ page }) => {
100103
await test.step('Attempt XSS in username field', async () => {
101104
await loginPage.login("<script>alert('XSS')</script>", 'admin123');
105+
await loginPage.errorMessage.waitFor({ state: 'visible', timeout: 10000 });
102106
});
103107

104108
await test.step('Verify no script execution', async () => {

automated-testing/tests/ui/pim.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test.describe('PIM Module Tests', () => {
1717

1818
// Login before each test
1919
await loginPage.goto();
20-
await loginPage.login('Admin', 'admin123');
20+
await loginPage.loginAndWaitForDashboard('Admin', 'admin123');
2121
await expect(page).toHaveURL(/.*dashboard/);
2222
await dashboardPage.navigateToPIM();
2323
});
@@ -53,9 +53,7 @@ test.describe('PIM Module Tests', () => {
5353
});
5454

5555
await test.step('Verify employee is saved', async () => {
56-
// Wait for save to complete and page redirect
57-
await page.waitForTimeout(3000);
58-
await expect(page.getByText('Personal Details')).toBeVisible();
56+
await expect(page.getByText('Personal Details')).toBeVisible({ timeout: 30000 });
5957
});
6058
});
6159

0 commit comments

Comments
 (0)