Files
openobserve/tests/ui-testing/playwright-tests/utils/queryBuilder-helpers.js
T
Shrinath RaoandClaude Opus 4.7 916cc79c5c fix: restore search priming in QB lite init, fix SQL OFF filter parsing (#11823)
## Summary
- Restores `applyQueryButton` call in `initQueryBuilderTestLite` — the
initial match_all search serves as a UI priming step that ensures the
auto-search from stream selection has completed before the test runs its
own query
- Adds `runQueryAndWaitForResults` before `clickBuildToggle` in SQL OFF
mode tests — matching the flow in `setupQueryAndSwitchToBuild` so the
builder has query results to parse into filters

## Root Cause
PR #11797 moved ingestion from `beforeEach` to `beforeAll` and
introduced `initQueryBuilderTestLite` which skipped the initial
match_all search. Two issues emerged:

1. **No UI priming**: After `selectStream`, an auto-search fires
automatically. Without waiting for it to complete, the test's own query
could run while the UI was in an intermediate state, causing the builder
to parse zero filter conditions.

2. **SQL OFF tests skipped query execution**: These tests set search bar
content and clicked build toggle without running the query first. The
builder had no executed query results to parse into filters.

## Changes
| File | Change |
|------|--------|
| `queryBuilder-helpers.js` | Add `applyQueryButton(pm)` to
`initQueryBuilderTestLite` (same as full init) |
| `logsQueryBuilder-filters-advanced.spec.js` | Add
`runQueryAndWaitForResults()` before `clickBuildToggle()` in 2 SQL OFF
tests |

## Test Results
- Local (5 workers, 77 tests): **74 passed**, 3 pre-existing
intermittent failures (CTE chart type, auto-mode chart type, NOT LIKE
filter parsing)
- The 8 CI flaky tests from #11797 are all in the passing set

## Test plan
- [ ] CI: Logs-Builder-Basic and Logs-Builder-Advanced shards pass with
0 flaky tests
- [ ] All 77 QB tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 10:38:31 +00:00

70 lines
2.5 KiB
JavaScript

const testLogger = require('./test-logger.js');
const logData = require('../../fixtures/log.json');
const logsdata = require('../../../test-data/logs_data.json');
const { getOrgIdentifier, getAuthHeaders } = require('./cloud-auth.js');
/**
* Ingest test data via Playwright request fixture (for beforeAll).
* Uses the request APIRequestContext — no browser page needed.
*/
async function ingestForQueryBuilderTest(request, streamName = "e2e_automate") {
const orgId = getOrgIdentifier();
const headers = getAuthHeaders();
const baseUrl = process.env.INGESTION_URL.endsWith('/')
? process.env.INGESTION_URL.slice(0, -1)
: process.env.INGESTION_URL;
const response = await request.post(`${baseUrl}/api/${orgId}/${streamName}/_json`, {
headers: headers,
data: logsdata
});
if (!response.ok()) throw new Error(`Ingestion failed: ${response.status()} ${await response.text()}`);
const responseData = await response.json();
testLogger.debug('Test data ingestion response', { response: responseData, streamName });
return responseData;
}
async function applyQueryButton(pm) {
const searchPromise = pm.page.waitForResponse(
response => response.url().includes('/_search') && response.status() === 200,
{ timeout: 60000 }
);
await pm.logsPage.clickRefreshButton();
try {
await searchPromise;
testLogger.info('Search query completed successfully');
} catch (error) {
testLogger.warn('Search response wait timed out, continuing test');
await pm.page.waitForLoadState('networkidle').catch(() => {});
}
}
async function setupQueryAndSwitchToBuild(pm, page, query) {
await pm.logsPage.enableSqlModeIfNeeded();
await page.waitForLoadState('domcontentloaded');
await pm.logsPage.setQueryEditorContent(query);
await pm.logsPage.runQueryAndWaitForResults();
await pm.logsPage.clickBuildToggle();
await pm.logsPage.waitForBuildTabLoaded();
}
/**
* Full init: navigate, select stream, run initial match_all query.
* Ingestion is handled by ingestForQueryBuilderTest in beforeAll.
*/
async function initQueryBuilderTest(page, pm) {
await page.waitForLoadState('domcontentloaded');
await page.goto(`${logData.logsUrl}?org_identifier=${getOrgIdentifier()}`);
await pm.logsPage.selectStream("e2e_automate");
await applyQueryButton(pm);
}
module.exports = {
ingestForQueryBuilderTest,
applyQueryButton,
setupQueryAndSwitchToBuild,
initQueryBuilderTest,
};