test: fix instance ai playwright benchmarks

This commit is contained in:
Oleg Ivaniv 2026-05-07 11:13:36 +02:00
parent a4b4eac220
commit 2885181b15
No known key found for this signature in database
3 changed files with 17 additions and 12 deletions

View File

@ -233,20 +233,20 @@ export class NavigationHelper {
* confirms to advance to the gateway step, then closes via Escape the
* gateway step has `close-on-press-escape` and does not auto-dismiss.
*/
private async dismissInstanceAiOptinModalIfPresent(): Promise<void> {
const enableToggle = this.page.getByTestId('instance-ai-welcome-modal-toggle-enable');
async dismissInstanceAiOptinModalIfPresent(page?: Page): Promise<void> {
const enableToggle = (page ?? this.page).getByTestId('instance-ai-welcome-modal-toggle-enable');
try {
await enableToggle.waitFor({ state: 'visible', timeout: 3_000 });
} catch {
return;
}
await enableToggle.click();
const confirm = this.page.getByTestId('instance-ai-welcome-modal-confirm');
const confirm = (page ?? this.page).getByTestId('instance-ai-welcome-modal-confirm');
await confirm.click();
// After confirming enable, the modal advances to the gateway step,
// which has no dedicated test-id for the skip button. Escape closes it.
await this.page.keyboard.press('Escape');
await this.page
await (page ?? this.page).keyboard.press('Escape');
await (page ?? this.page)
.getByTestId('instance-ai-welcome-modal-toggle-enable')
.waitFor({ state: 'hidden', timeout: 5_000 });
}

View File

@ -38,12 +38,14 @@ test.describe(
const ai = new InstanceAiPage(page);
await page.goto('/instance-ai');
await n8n.navigate.dismissInstanceAiOptinModalIfPresent(page);
await ai.getContainer().waitFor({ state: 'visible', timeout: 15_000 });
await ai.getChatInput().waitFor({ state: 'visible', timeout: 10_000 });
await ai.openSidebar();
await ai.sidebar.getNewThreadButton().click();
await page.waitForURL(/\/instance-ai\/[0-9a-f-]+/, { timeout: 10_000 });
// await page.waitForURL(/\/instance-ai\/[0-9a-f-]+/, { timeout: 10_000 });
const threadId = page.url().match(/\/instance-ai\/([0-9a-f-]+)/)?.[1];
// const threadId = page.url().match(/\/instance-ai\/([0-9a-f-]+)/)?.[1];
await ai.getChatInput().fill(BENCHMARK_PROMPTS[i % BENCHMARK_PROMPTS.length]);
await ai.getSendButton().click();
@ -53,10 +55,10 @@ test.describe(
await ai.getStopButton().click();
await ai.waitForRunComplete(30_000);
console.log(`[CANCEL ${i + 1}] Cancelled thread ${threadId}`);
// console.log(`[CANCEL ${i + 1}] Cancelled thread ${threadId}`);
await page.close();
if (threadId) await driver.deleteThread(threadId);
// if (threadId) await driver.deleteThread(threadId);
},
measureAfter: (i + 1) % 2 === 0 || i === CANCEL_ITERATIONS - 1,
});

View File

@ -106,19 +106,22 @@ export class InstanceAiDriver {
// Navigate and wait for UI ready
await page.goto('/instance-ai');
await this.n8n.navigate.dismissInstanceAiOptinModalIfPresent(page);
await ai.getContainer().waitFor({ state: 'visible', timeout: 15_000 });
await ai.getChatInput().waitFor({ state: 'visible', timeout: 10_000 });
// Create thread (click new chat, wait for URL)
await ai.openSidebar();
await ai.sidebar.getNewThreadButton().click();
await page.waitForURL(/\/instance-ai\/[0-9a-f-]+/, { timeout: 10_000 });
const threadId = this.extractThreadId(page);
this.createdThreadIds.push(threadId);
// Send the prompt
await ai.getChatInput().fill(prompt);
await ai.getSendButton().click();
await page.waitForURL(/\/instance-ai\/[0-9a-f-]+/, { timeout: 10_000 });
const threadId = this.extractThreadId(page);
this.createdThreadIds.push(threadId);
console.log(`[INSTANCE-AI] Tab ${i + 1}: sent prompt, thread ${threadId}`);
return { page, ai, threadId, prompt, startTime: Date.now() };
}),