Skip to content

Commit e501f88

Browse files
committed
Remove networkidle and role=alert waits, use text-based Save&Test result detection
- Remove waitForLoadState('networkidle') - hangs on 11.x WebSocket connections - Remove waitForSelector('[role=alert]') - not present in 9.x - Add waitForSaveTestResult() that waits for 'Data source is working' or 'Data source is not working' text (reliable across all Grafana versions) - Remove waitForSelector from setup functions (no longer needed) - Simplify wrong-credentials tests to assert ok===false
1 parent 95a2ec7 commit e501f88

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/e2e.test.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ async function login(page: Page) {
1818
await sel(page, 'Password input field').fill('admin');
1919
await sel(page, 'Login button').click();
2020
await sel(page, 'Skip change password button').click();
21-
await page.waitForLoadState('networkidle');
2221
}
2322

2423
async function goToTrinoSettings(page: Page) {
@@ -32,6 +31,15 @@ async function goToTrinoSettings(page: Page) {
3231
}
3332
}
3433

34+
// Wait for Save & Test response: "Data source is working" or any error text
35+
async function waitForSaveTestResult(page: Page): Promise<boolean> {
36+
const success = page.getByText('Data source is working');
37+
const error = page.getByText('Data source is not working');
38+
// Wait for either success or failure message
39+
await success.or(error).waitFor({ timeout: 30000 });
40+
return await success.isVisible();
41+
}
42+
3543
async function setupDataSourceWithAccessToken(page: Page) {
3644
await sel(page, 'Datasource HTTP settings url').fill('http://trino:8080');
3745
if (isNewGrafana) {
@@ -41,7 +49,6 @@ async function setupDataSourceWithAccessToken(page: Page) {
4149
}
4250
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
4351
await sel(page, 'Data source settings page Save and Test button').click();
44-
await page.waitForSelector('[role="alert"]', { timeout: 10000 });
4552
}
4653

4754
async function setupDataSourceWithClientCredentials(page: Page, clientId: string) {
@@ -51,7 +58,6 @@ async function setupDataSourceWithClientCredentials(page: Page, clientId: string
5158
await page.locator('div').filter({hasText: /^Client secret$/}).locator('input[type="password"]').fill('grafana-secret');
5259
await page.locator('div').filter({hasText: /^Impersonation user$/}).locator('input').fill('service-account-grafana-client');
5360
await sel(page, 'Data source settings page Save and Test button').click();
54-
await page.waitForSelector('[role="alert"]', { timeout: 10000 });
5561
}
5662

5763
async function runQueryAndCheckResults(page: Page) {
@@ -80,33 +86,33 @@ test('test with access token', async ({ page }) => {
8086
await login(page);
8187
await goToTrinoSettings(page);
8288
await setupDataSourceWithAccessToken(page);
89+
const ok = await waitForSaveTestResult(page);
90+
expect(ok).toBe(true);
8391
await runQueryAndCheckResults(page);
8492
});
8593

8694
test('test client credentials flow', async ({ page }) => {
8795
await login(page);
8896
await goToTrinoSettings(page);
8997
await setupDataSourceWithClientCredentials(page, GRAFANA_CLIENT);
98+
const ok = await waitForSaveTestResult(page);
99+
expect(ok).toBe(true);
90100
await runQueryAndCheckResults(page);
91101
});
92102

93103
test('test client credentials flow with wrong credentials', async ({ page }) => {
94104
await login(page);
95105
await goToTrinoSettings(page);
96106
await setupDataSourceWithClientCredentials(page, "some-wrong-client");
97-
// Alert is already visible (setupDataSourceWithClientCredentials waits for it).
98-
// Verify it is NOT the success message.
99-
await expect(page.locator('[role="alert"]').first()).toBeVisible({ timeout: 10000 });
100-
await expect(page.locator('[role="alert"]').filter({ hasText: 'Data source is working' })).toHaveCount(0);
107+
const ok = await waitForSaveTestResult(page);
108+
expect(ok).toBe(false);
101109
});
102110

103111
test('test client credentials flow with configured access token', async ({ page }) => {
104112
await login(page);
105113
await goToTrinoSettings(page);
106114
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
107115
await setupDataSourceWithClientCredentials(page, GRAFANA_CLIENT);
108-
// Alert is already visible (setupDataSourceWithClientCredentials waits for it).
109-
// Verify it is NOT the success message.
110-
await expect(page.locator('[role="alert"]').first()).toBeVisible({ timeout: 10000 });
111-
await expect(page.locator('[role="alert"]').filter({ hasText: 'Data source is working' })).toHaveCount(0);
116+
const ok = await waitForSaveTestResult(page);
117+
expect(ok).toBe(false);
112118
});

0 commit comments

Comments
 (0)