Skip to content

Commit fd1cf34

Browse files
authored
fix(e2e): resolve histogram bar chart canvas click timeout (#9628)
## Summary - Fix TimeoutError in `logsqueries.spec.js` histogram bar chart test caused by ECharts canvas DOM re-rendering - Add retry mechanism to `clickBarChartCanvas()` to handle canvas element detachment - Add proper assertions using page object pattern ## Changes - **logsPage.js**: Added retry mechanism (3 attempts) with network idle wait and stabilization delay - **logsPage.js**: Added `expectBarChartCanvasVisible()` assertion method - **logsqueries.spec.js**: Ensure histogram toggle is ON before test - **logsqueries.spec.js**: Use `waitForLoadState('networkidle')` for reliability - **logsqueries.spec.js**: Add visibility assertions before clicking canvas ## Test plan - [x] Test passes locally - [x] Test passes on repeat runs (verified with `--repeat-each=2`) - [x] Sentinel code quality audit passed
1 parent e52d000 commit fd1cf34

File tree

2 files changed

+68
-7
lines changed

2 files changed

+68
-7
lines changed

tests/ui-testing/pages/logsPages/logsPage.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,9 +1572,42 @@ export class LogsPage {
15721572
}
15731573

15741574
async clickBarChartCanvas() {
1575-
return await this.page.locator(this.barChartCanvas).click({
1576-
position: { x: 182, y: 66 }
1577-
});
1575+
// Wait for network idle to ensure chart data has loaded
1576+
await this.page.waitForLoadState('networkidle');
1577+
1578+
const canvasLocator = this.page.locator(this.barChartCanvas);
1579+
1580+
// Retry mechanism to handle ECharts canvas re-rendering
1581+
const maxRetries = 3;
1582+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
1583+
try {
1584+
// Wait for the canvas to be visible
1585+
await canvasLocator.waitFor({ state: 'visible', timeout: 30000 });
1586+
1587+
// Wait for chart to stabilize - ECharts may re-render multiple times
1588+
await this.page.waitForTimeout(2000);
1589+
1590+
// force:true required for ECharts canvas - canvas elements are interactive
1591+
// but fail Playwright's actionability checks (no pointer-events in traditional sense)
1592+
await canvasLocator.click({
1593+
position: { x: 182, y: 66 },
1594+
force: true,
1595+
timeout: 10000
1596+
});
1597+
return; // Success
1598+
} catch (error) {
1599+
if (attempt === maxRetries) {
1600+
throw error;
1601+
}
1602+
// Wait before retry to allow chart to stabilize
1603+
await this.page.waitForTimeout(1000);
1604+
}
1605+
}
1606+
}
1607+
1608+
async expectBarChartCanvasVisible() {
1609+
const canvasLocator = this.page.locator(this.barChartCanvas);
1610+
return await expect(canvasLocator).toBeVisible({ timeout: 30000 });
15781611
}
15791612

15801613
async fillIndexFieldSearchInput(text) {

tests/ui-testing/playwright-tests/Logs/logsqueries.spec.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ test.describe("Logs Queries testcases", () => {
7878
await page.goto(
7979
`${logData.logsUrl}?org_identifier=${process.env["ORGNAME"]}`
8080
);
81-
const allsearch = page.waitForResponse("**/api/default/_search**");
82-
await pm.logsPage.selectStream("e2e_automate");
81+
await pm.logsPage.selectStream("e2e_automate");
8382
await applyQueryButton(page);
84-
83+
8584
testLogger.info('Logs queries test setup completed');
8685
});
8786

@@ -319,20 +318,49 @@ test.describe("Logs Queries testcases", () => {
319318
tag: ['@histogramBarChart', '@histogram', '@all', '@logs']
320319
}, async ({ page }) => {
321320
testLogger.info('Testing bar chart display with histogram toggle');
321+
322+
// Ensure histogram is ON before testing bar chart
323+
const isHistogramOn = await pm.logsPage.isHistogramOn();
324+
if (!isHistogramOn) {
325+
await pm.logsPage.toggleHistogram();
326+
await pm.logsPage.waitForTimeout(1000);
327+
}
328+
322329
await pm.logsPage.clickLogSearchIndexListFieldSearchInput();
323330
await pm.logsPage.fillLogSearchIndexListFieldSearchInput('code');
324331
await pm.logsPage.waitForTimeout(4000);
325332
await pm.logsPage.clickExpandCode();
326333
await pm.logsPage.waitForTimeout(4000);
334+
335+
// Click refresh and wait for network to settle
327336
await pm.logsPage.clickRefreshButton();
337+
await page.waitForLoadState('networkidle', { timeout: 30000 })
338+
.catch((e) => testLogger.debug('networkidle timeout (non-blocking)', { error: e.message }));
339+
await pm.logsPage.waitForTimeout(2000);
340+
341+
// Toggle SQL mode and refresh
328342
await pm.logsPage.clickSQLModeToggle();
329343
await pm.logsPage.clickRefreshButton();
344+
await page.waitForLoadState('networkidle', { timeout: 30000 })
345+
.catch((e) => testLogger.debug('networkidle timeout (non-blocking)', { error: e.message }));
346+
await pm.logsPage.waitForTimeout(2000);
347+
348+
// Verify bar chart is visible in SQL mode then click
349+
await pm.logsPage.expectBarChartCanvasVisible();
330350
await pm.logsPage.clickBarChartCanvas();
351+
352+
// Toggle SQL mode off and refresh
331353
await pm.logsPage.clickSQLModeToggle();
332354
await pm.logsPage.clickRefreshButton();
355+
await page.waitForLoadState('networkidle', { timeout: 30000 })
356+
.catch((e) => testLogger.debug('networkidle timeout (non-blocking)', { error: e.message }));
357+
await pm.logsPage.waitForTimeout(2000);
358+
359+
// Verify bar chart is visible in non-SQL mode then click
360+
await pm.logsPage.expectBarChartCanvasVisible();
333361
await pm.logsPage.clickBarChartCanvas();
334362
await pm.logsPage.clickHistogramToggleDiv();
335-
363+
336364
testLogger.info('Histogram bar chart display test completed');
337365
});
338366

0 commit comments

Comments
 (0)