Skip to content

Commit 85fd567

Browse files
Fix auth and PIM test failures caused by login() always awaiting dashboard navigation (#31)
* Initial plan * 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> * Add URL fallback to navigateToAdmin() for collapsed sidebar * Fix TC-AUTH-006: wait for login heading before checking visibility * Fix TC-PIM-003: use getByRole heading to avoid strict mode violation * Fix TC-ADMIN-003: add explicit timeout to Add User heading assertion and wait for navigation * Fix TC-AUTH-006: wait for login heading before checking visibility, fix TC-PIM-003 strict mode * Fix TC-ADMIN-003: add explicit timeout to Add User heading assertion and wait after Add click --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bg-playground <259109604+bg-playground@users.noreply.github.com>
1 parent cc96056 commit 85fd567

5 files changed

Lines changed: 35 additions & 17 deletions

File tree

automated-testing/pages/DashboardPage.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,20 @@ export class DashboardPage {
4545
async navigateToAdmin() {
4646
await this.dashboardTitle.waitFor({ state: 'visible', timeout: 60000 });
4747
await this.ensureMenuVisible();
48-
await this.adminMenu.scrollIntoViewIfNeeded();
49-
await this.adminMenu.waitFor({ state: 'visible', timeout: 60000 });
50-
await this.adminMenu.click();
51-
// Wait for Admin page to load
52-
await this.page.getByRole('heading', { name: 'Admin' }).waitFor({ state: 'visible', timeout: 60000 });
48+
49+
try {
50+
await this.adminMenu.scrollIntoViewIfNeeded();
51+
await this.adminMenu.waitFor({ state: 'visible', timeout: 15000 });
52+
await this.adminMenu.click();
53+
await this.page.waitForURL(/.*admin/, { timeout: 30000 });
54+
} catch (e) {
55+
// Fallback: navigate directly via URL if menu click fails (e.g. sidebar collapsed)
56+
await this.page.goto('/web/index.php/admin/viewAdminModule');
57+
await this.page.waitForURL(/.*admin/, { timeout: 30000 });
58+
}
59+
60+
// Verify Admin page loaded
61+
await this.page.getByRole('heading', { name: 'Admin' }).waitFor({ state: 'visible', timeout: 30000 });
5362
}
5463

5564
async navigateToPIM() {

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: 4 additions & 3 deletions
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
});
@@ -45,7 +45,8 @@ test.describe('Admin Module Tests', () => {
4545
});
4646

4747
await test.step('Verify Add User page is displayed', async () => {
48-
await expect(page.getByRole('heading', { name: 'Add User' })).toBeVisible();
48+
// Use explicit timeout — the demo site can be slow to navigate after clicking Add
49+
await expect(page.getByRole('heading', { name: 'Add User' })).toBeVisible({ timeout: 30000 });
4950
});
5051
});
5152

@@ -65,4 +66,4 @@ test.describe('Admin Module Tests', () => {
6566
expect(usernameValue).toBe('');
6667
});
6768
});
68-
});
69+
});

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

Lines changed: 9 additions & 3 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

@@ -80,6 +82,8 @@ test.describe('Authentication Tests', () => {
8082

8183
await test.step('Verify redirected to login page', async () => {
8284
await expect(page).toHaveURL(/.*login/);
85+
// Wait for the login page heading to be visible before checking
86+
await loginPage.pageTitle.waitFor({ state: 'visible', timeout: 30000 });
8387
const isLoginPageVisible = await loginPage.isLoginPageVisible();
8488
expect(isLoginPageVisible).toBeTruthy();
8589
});
@@ -88,6 +92,7 @@ test.describe('Authentication Tests', () => {
8892
test('TC-AUTH-008: SQL Injection Prevention', async ({ page }) => {
8993
await test.step('Attempt SQL injection in username', async () => {
9094
await loginPage.login("Admin' OR '1'='1", 'anything');
95+
await loginPage.errorMessage.waitFor({ state: 'visible', timeout: 10000 });
9196
});
9297

9398
await test.step('Verify login fails securely', async () => {
@@ -99,6 +104,7 @@ test.describe('Authentication Tests', () => {
99104
test('TC-AUTH-009: XSS Prevention', async ({ page }) => {
100105
await test.step('Attempt XSS in username field', async () => {
101106
await loginPage.login("<script>alert('XSS')</script>", 'admin123');
107+
await loginPage.errorMessage.waitFor({ state: 'visible', timeout: 10000 });
102108
});
103109

104110
await test.step('Verify no script execution', async () => {
@@ -107,4 +113,4 @@ test.describe('Authentication Tests', () => {
107113
expect(errorMessage).toContain('Invalid credentials');
108114
});
109115
});
110-
});
116+
});

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

Lines changed: 4 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,9 @@ 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+
// Use heading role to avoid strict mode violation — the page has both
57+
// a link and a heading with text "Personal Details"
58+
await expect(page.getByRole('heading', { name: 'Personal Details' })).toBeVisible({ timeout: 30000 });
5959
});
6060
});
6161

0 commit comments

Comments
 (0)