From 2885181b152c281f59093338ca2837667352bfe5 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Thu, 7 May 2026 11:13:36 +0200 Subject: [PATCH] test: fix instance ai playwright benchmarks --- .../testing/playwright/helpers/NavigationHelper.ts | 10 +++++----- .../benchmarks-local/instance-ai/cancel-abort.spec.ts | 10 ++++++---- .../playwright/utils/benchmark/instance-ai-driver.ts | 9 ++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/testing/playwright/helpers/NavigationHelper.ts b/packages/testing/playwright/helpers/NavigationHelper.ts index 45bc08d9823..ecb80a39e7d 100644 --- a/packages/testing/playwright/helpers/NavigationHelper.ts +++ b/packages/testing/playwright/helpers/NavigationHelper.ts @@ -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 { - const enableToggle = this.page.getByTestId('instance-ai-welcome-modal-toggle-enable'); + async dismissInstanceAiOptinModalIfPresent(page?: Page): Promise { + 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 }); } diff --git a/packages/testing/playwright/tests/infrastructure/benchmarks-local/instance-ai/cancel-abort.spec.ts b/packages/testing/playwright/tests/infrastructure/benchmarks-local/instance-ai/cancel-abort.spec.ts index ff9b888da3f..839a9bbf2c5 100644 --- a/packages/testing/playwright/tests/infrastructure/benchmarks-local/instance-ai/cancel-abort.spec.ts +++ b/packages/testing/playwright/tests/infrastructure/benchmarks-local/instance-ai/cancel-abort.spec.ts @@ -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, }); diff --git a/packages/testing/playwright/utils/benchmark/instance-ai-driver.ts b/packages/testing/playwright/utils/benchmark/instance-ai-driver.ts index bd2ffbde6a6..1afbc8ca5ce 100644 --- a/packages/testing/playwright/utils/benchmark/instance-ai-driver.ts +++ b/packages/testing/playwright/utils/benchmark/instance-ai-driver.ts @@ -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() }; }),