Skip to content

Commit a6e55c2

Browse files
author
Mohammod Al Amin Ashik
committed
fix: scope toast-container locators to main content area in e2e tests
SpaceSwitcher in the sidebar also renders a ToastContainer, causing Playwright strict mode violations when getByTestId('toast-container') resolves to 2 elements. Scoped all toast locators to page.getByRole('main') to target only the main content area.
1 parent 5438177 commit a6e55c2

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

tests/e2e/pages/BasePage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export abstract class BasePage {
7373
* Get text content of the first visible toast
7474
*/
7575
async getToastText(): Promise<string | null> {
76-
const toast = this.page.getByTestId('toast-container').locator('[role="alert"]').first();
76+
const toast = this.page.getByRole('main').getByTestId('toast-container').locator('[role="alert"]').first();
7777
return toast.textContent();
7878
}
7979

@@ -85,9 +85,9 @@ export abstract class BasePage {
8585
}
8686

8787
/**
88-
* Assert that a toast container is present in the DOM
88+
* Assert that a toast container is present in the main content area
8989
*/
9090
get toastContainer(): Locator {
91-
return this.page.getByTestId('toast-container');
91+
return this.page.getByRole('main').getByTestId('toast-container');
9292
}
9393
}

tests/e2e/pages/SettingsPage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class SettingsPage extends BasePage {
2727
this.autoLaunchSwitch = page.getByTestId('auto-launch-switch');
2828
this.startMinimizedSwitch = page.getByTestId('start-minimized-switch');
2929
this.closeToTraySwitch = page.getByTestId('close-to-tray-switch');
30-
this.toastContainer = page.getByTestId('toast-container');
30+
this.toastContainer = page.getByRole('main').getByTestId('toast-container');
3131
}
3232

3333
async selectTheme(theme: 'light' | 'dark' | 'system') {
@@ -60,7 +60,7 @@ export class SettingsPage extends BasePage {
6060
}
6161

6262
async getToastText() {
63-
const toast = this.page.getByTestId('toast-container').locator('[role="alert"]').first();
63+
const toast = this.page.getByRole('main').getByTestId('toast-container').locator('[role="alert"]').first();
6464
return toast.textContent();
6565
}
6666

tests/e2e/specs/featuresets.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test.describe('Feature Set Toast Container', () => {
8080
await page.locator('nav button:has-text("FeatureSets")').click({ force: true });
8181
await expect(page.getByRole('heading', { name: 'Feature Sets' }).first()).toBeVisible();
8282

83-
await expect(page.getByTestId('toast-container')).toBeAttached();
83+
await expect(page.getByRole('main').getByTestId('toast-container')).toBeAttached();
8484
});
8585
});
8686

@@ -176,8 +176,8 @@ test.describe('Feature Set Panel Save Toast', () => {
176176
await page.getByRole('button', { name: /Save Changes/i }).click();
177177

178178
// Wait for success toast
179-
await expect(page.getByTestId('toast-success')).toBeVisible({ timeout: 5000 });
180-
const toastText = await page.getByTestId('toast-container').locator('[role="alert"]').first().textContent();
179+
await expect(page.getByTestId('toast-success').first()).toBeVisible({ timeout: 5000 });
180+
const toastText = await page.getByRole('main').getByTestId('toast-container').locator('[role="alert"]').first().textContent();
181181
expect(toastText).toContain('Changes saved');
182182
}
183183
});
@@ -201,8 +201,8 @@ test.describe('Feature Set Panel Save Toast', () => {
201201
if (await saveButton.isVisible()) {
202202
await saveButton.click();
203203

204-
await expect(page.getByTestId('toast-error')).toBeVisible({ timeout: 5000 });
205-
const toastText = await page.getByTestId('toast-container').locator('[role="alert"]').first().textContent();
204+
await expect(page.getByTestId('toast-error').first()).toBeVisible({ timeout: 5000 });
205+
const toastText = await page.getByRole('main').getByTestId('toast-container').locator('[role="alert"]').first().textContent();
206206
expect(toastText).toContain('Failed to save');
207207
}
208208
}

tests/e2e/specs/servers.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ test.describe('Server Toast Notifications', () => {
126126
if (await clearBtn.isVisible()) {
127127
await clearBtn.click();
128128

129-
await expect(page.getByTestId('toast-success')).toBeVisible({ timeout: 5000 });
130-
const toastText = await page.getByTestId('toast-container').locator('[role="alert"]').first().textContent();
129+
await expect(page.getByTestId('toast-success').first()).toBeVisible({ timeout: 5000 });
130+
const toastText = await page.getByRole('main').getByTestId('toast-container').locator('[role="alert"]').first().textContent();
131131
expect(toastText).toContain('Logs cleared');
132132
}
133133
}
@@ -149,8 +149,8 @@ test.describe('Server Toast Notifications', () => {
149149
if (await copyBtn.isVisible()) {
150150
await copyBtn.click();
151151

152-
await expect(page.getByTestId('toast-success')).toBeVisible({ timeout: 5000 });
153-
const toastText = await page.getByTestId('toast-container').locator('[role="alert"]').first().textContent();
152+
await expect(page.getByTestId('toast-success').first()).toBeVisible({ timeout: 5000 });
153+
const toastText = await page.getByRole('main').getByTestId('toast-container').locator('[role="alert"]').first().textContent();
154154
expect(toastText).toContain('Path copied');
155155
}
156156
}

tests/e2e/specs/settings.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ test.describe('Settings', () => {
303303

304304
await page.locator('nav button:has-text("Settings")').click();
305305

306-
// Toast container should exist (even if empty)
307-
const toastContainer = page.getByTestId('toast-container');
306+
// Toast container should exist in main content (even if empty)
307+
const toastContainer = page.getByRole('main').getByTestId('toast-container');
308308
await expect(toastContainer).toBeAttached();
309309
});
310310

0 commit comments

Comments
 (0)