test: e2e-pagination-fix (#9245)

This commit is contained in:
Neha P
2025-11-22 08:30:59 +05:30
committed by GitHub
parent 19140b8e7b
commit bdfd24525d
2 changed files with 110 additions and 0 deletions
@@ -1783,6 +1783,29 @@ export class LogsPage {
return await expect(this.page.locator(this.pagination)).not.toBeVisible();
}
async expectResultPaginationVisible() {
return await expect(this.page.locator(this.resultPagination)).toBeVisible();
}
async clickPaginationPage(pageNumber) {
return await this.page.locator(`${this.resultPagination} .q-btn`).filter({ hasText: pageNumber.toString() }).first().click();
}
async getPaginationPageCount() {
const pageButtons = this.page.locator(`${this.resultPagination} .q-btn`).filter({ hasText: /^\d+$/ });
return await pageButtons.count();
}
async getPaginationPageClasses(pageNumber) {
const pageButton = this.page.locator(`${this.resultPagination} .q-btn`).filter({ hasText: pageNumber.toString() }).first();
return await pageButton.getAttribute('class');
}
async isPaginationPageActive(pageNumber) {
const classes = await this.getPaginationPageClasses(pageNumber);
return classes && (classes.includes('bg-primary') || classes.includes('unelevated'));
}
async expectSQLPaginationNotVisible() {
return await expect(this.page.locator(this.sqlPagination)).not.toBeVisible();
}
@@ -453,4 +453,91 @@ test.describe("Logs Queries testcases", () => {
testLogger.info('Pagination SQL group/order/limit query test completed');
});
test("should reset pagination to page 1 after running query again", {
tag: ['@pagination', '@logs', '@all']
}, async ({ page }) => {
testLogger.info('Testing pagination reset behavior after re-running query');
// Set up conditions to ensure we have enough data for pagination
await pm.logsPage.waitForTimeout(2000);
await pm.logsPage.clickDateTimeButton();
await pm.logsPage.waitForTimeout(1000);
// Use wider time range to capture ingested data
const oneHourButton = page.getByText('Last 1 hour');
const twelveHourButton = page.getByText('Last 12 hours');
if (await oneHourButton.isVisible({ timeout: 2000 }).catch(() => false)) {
await oneHourButton.click();
testLogger.info('Set time range to Last 1 hour to capture ingested data');
} else if (await twelveHourButton.isVisible({ timeout: 2000 }).catch(() => false)) {
await twelveHourButton.click();
testLogger.info('Set time range to Last 12 hours to capture ingested data');
} else {
await pm.logsPage.clickRelative15MinButton();
testLogger.info('Fallback to 15 minute time range');
}
// Run initial query to get results
await pm.logsPage.clickRefreshButton();
await pm.logsPage.waitForTimeout(3000);
// Pagination should exist after ingesting data - expect it to be visible
await pm.logsPage.expectResultPaginationVisible();
testLogger.info('Pagination controls found, proceeding with test');
// Get available page count using POM
const pageCount = await pm.logsPage.getPaginationPageCount();
testLogger.info(`Found ${pageCount} page buttons`);
// Navigate to page 4 using POM
testLogger.info('Navigating to page 4');
await pm.logsPage.clickPaginationPage(4);
await pm.logsPage.waitForTimeout(2000);
// Verify we're on page 4 using POM
await pm.logsPage.waitForTimeout(3000);
const page4Classes = await pm.logsPage.getPaginationPageClasses(4);
testLogger.info(`Page 4 button classes: ${page4Classes}`);
// Run query again while on page 4
testLogger.info('Running query again while on page 4');
await pm.logsPage.clickRefreshButton();
await pm.logsPage.waitForTimeout(3000);
// Verify pagination resets to page 1 using POM
await pm.logsPage.waitForTimeout(2000);
const page4ClassesAfter = await pm.logsPage.getPaginationPageClasses(4).catch(() => null);
const page1ClassesAfter = await pm.logsPage.getPaginationPageClasses(1).catch(() => null);
testLogger.info(`After query - Page 1 classes: ${page1ClassesAfter}`);
testLogger.info(`After query - Page 4 classes: ${page4ClassesAfter}`);
// Check pagination state using POM methods
const isStillOnPage4 = await pm.logsPage.isPaginationPageActive(4).catch(() => false);
const isBackToPage1 = await pm.logsPage.isPaginationPageActive(1).catch(() => false);
if (isStillOnPage4) {
testLogger.error('🐛 BUG DETECTED: Pagination stayed on page 4 instead of resetting to page 1');
expect(isStillOnPage4).toBeFalsy();
} else if (isBackToPage1) {
testLogger.info('✅ Pagination correctly reset to page 1 after re-running query');
expect(isBackToPage1).toBeTruthy();
} else {
testLogger.info('Using fallback method to check pagination state');
const activePage = await page.locator('[data-test="logs-search-result-pagination"] .q-btn--unelevated').first().textContent({ timeout: 5000 }).catch(() => 'unknown');
testLogger.info(`Active page (fallback): ${activePage}`);
if (activePage === '4') {
testLogger.error('🐛 BUG DETECTED: Pagination stayed on page 4 (fallback method)');
expect(activePage).toBe('1');
} else {
testLogger.info('✅ Pagination appears to have reset correctly (fallback method)');
}
}
testLogger.info('Pagination reset behavior test completed');
});
});