From f83a808d39368419f205ca167257347ac864d1bf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 10 Aug 2025 22:03:03 +0000 Subject: [PATCH] Add response.addCode() calls to browser_wait_for tool and update tests Co-authored-by: pavelfeldman <883973+pavelfeldman@users.noreply.github.com> --- src/tools/wait.ts | 12 +++++++++--- tests/wait.spec.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/tools/wait.ts b/src/tools/wait.ts index 0d5e59d..2328fcb 100644 --- a/src/tools/wait.ts +++ b/src/tools/wait.ts @@ -39,7 +39,9 @@ const wait = defineTool({ const code: string[] = []; if (params.time) { - code.push(`await new Promise(f => setTimeout(f, ${params.time!} * 1000));`); + const timeCode = `await new Promise(f => setTimeout(f, ${params.time!} * 1000));`; + code.push(timeCode); + response.addCode(timeCode); await new Promise(f => setTimeout(f, Math.min(30000, params.time! * 1000))); } @@ -48,12 +50,16 @@ const wait = defineTool({ const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined; if (goneLocator) { - code.push(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`); + const goneCode = `await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`; + code.push(goneCode); + response.addCode(goneCode); await goneLocator.waitFor({ state: 'hidden' }); } if (locator) { - code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`); + const locatorCode = `await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`; + code.push(locatorCode); + response.addCode(locatorCode); await locator.waitFor({ state: 'visible' }); } diff --git a/tests/wait.spec.ts b/tests/wait.spec.ts index fcc38fe..704fa74 100644 --- a/tests/wait.spec.ts +++ b/tests/wait.spec.ts @@ -48,6 +48,7 @@ test('browser_wait_for(text)', async ({ client, server }) => { name: 'browser_wait_for', arguments: { text: 'Text to appear' }, })).toHaveResponse({ + code: `await page.getByText("Text to appear").first().waitFor({ state: 'visible' });`, pageState: expect.stringContaining(`- generic [ref=e3]: Text to appear`), }); }); @@ -84,6 +85,23 @@ test('browser_wait_for(textGone)', async ({ client, server }) => { name: 'browser_wait_for', arguments: { textGone: 'Text to disappear' }, })).toHaveResponse({ + code: `await page.getByText("Text to disappear").first().waitFor({ state: 'hidden' });`, pageState: expect.stringContaining(`- generic [ref=e3]: Text to appear`), }); }); + +test('browser_wait_for(time)', async ({ client, server }) => { + server.setContent('/', `
Hello World
`, 'text/html'); + + await client.callTool({ + name: 'browser_navigate', + arguments: { url: server.PREFIX }, + }); + + expect(await client.callTool({ + name: 'browser_wait_for', + arguments: { time: 1 }, + })).toHaveResponse({ + code: `await new Promise(f => setTimeout(f, 1 * 1000));`, + }); +});