From 2bf57e22c63929964bae47f8fa3f518524325c54 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 25 Jul 2025 15:54:18 -0700 Subject: [PATCH] chore: do not snapshot on fill (#767) --- src/tools/keyboard.ts | 4 +- tests/core.spec.ts | 58 -------------------- tests/type.spec.ts | 119 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 60 deletions(-) create mode 100644 tests/type.spec.ts diff --git a/src/tools/keyboard.ts b/src/tools/keyboard.ts index 9286f5c..c40b83f 100644 --- a/src/tools/keyboard.ts +++ b/src/tools/keyboard.ts @@ -62,12 +62,11 @@ const type = defineTabTool({ }, handle: async (tab, params, response) => { - response.setIncludeSnapshot(); - const locator = await tab.refLocator(params); await tab.waitForCompletion(async () => { if (params.slowly) { + response.setIncludeSnapshot(); response.addCode(`// Press "${params.text}" sequentially into "${params.element}"`); response.addCode(`await page.${await generateLocator(locator)}.pressSequentially(${javascript.quote(params.text)});`); await locator.pressSequentially(params.text); @@ -78,6 +77,7 @@ const type = defineTabTool({ } if (params.submit) { + response.setIncludeSnapshot(); response.addCode(`await page.${await generateLocator(locator)}.press('Enter');`); await locator.press('Enter'); } diff --git a/tests/core.spec.ts b/tests/core.spec.ts index abc6c77..4521a6b 100644 --- a/tests/core.spec.ts +++ b/tests/core.spec.ts @@ -120,64 +120,6 @@ await page.getByRole('listbox').selectOption(['bar', 'baz']); `); }); -test('browser_type', async ({ client, server }) => { - server.setContent('/', ` - - - - - `, 'text/html'); - - await client.callTool({ - name: 'browser_navigate', - arguments: { - url: server.PREFIX, - }, - }); - await client.callTool({ - name: 'browser_type', - arguments: { - element: 'textbox', - ref: 'e2', - text: 'Hi!', - submit: true, - }, - }); - expect(await client.callTool({ - name: 'browser_console_messages', - })).toHaveTextContent(/\[LOG\] Key pressed: Enter , Text: Hi!/); -}); - -test('browser_type (slowly)', async ({ client, server }) => { - server.setContent('/', ` - - `, 'text/html'); - - await client.callTool({ - name: 'browser_navigate', - arguments: { - url: server.PREFIX, - }, - }); - await client.callTool({ - name: 'browser_type', - arguments: { - element: 'textbox', - ref: 'e2', - text: 'Hi!', - submit: true, - slowly: true, - }, - }); - const response = await client.callTool({ - name: 'browser_console_messages', - }); - expect(response).toHaveTextContent(/\[LOG\] Key pressed: H Text: /); - expect(response).toHaveTextContent(/\[LOG\] Key pressed: i Text: H/); - expect(response).toHaveTextContent(/\[LOG\] Key pressed: ! Text: Hi/); - expect(response).toHaveTextContent(/\[LOG\] Key pressed: Enter Text: Hi!/); -}); - test('browser_resize', async ({ client, server }) => { server.setContent('/', ` Resize Test diff --git a/tests/type.spec.ts b/tests/type.spec.ts new file mode 100644 index 0000000..08b2007 --- /dev/null +++ b/tests/type.spec.ts @@ -0,0 +1,119 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { test, expect } from './fixtures.js'; + +test('browser_type', async ({ client, server }) => { + server.setContent('/', ` + + + + + `, 'text/html'); + + await client.callTool({ + name: 'browser_navigate', + arguments: { + url: server.PREFIX, + }, + }); + + { + const response = await client.callTool({ + name: 'browser_type', + arguments: { + element: 'textbox', + ref: 'e2', + text: 'Hi!', + submit: true, + }, + }); + expect(response).toContainTextContent(`fill('Hi!');`); + expect(response).toContainTextContent(`- textbox`); + } + + expect(await client.callTool({ + name: 'browser_console_messages', + })).toHaveTextContent(/\[LOG\] Key pressed: Enter , Text: Hi!/); +}); + +test('browser_type (slowly)', async ({ client, server }) => { + server.setContent('/', ` + + `, 'text/html'); + + await client.callTool({ + name: 'browser_navigate', + arguments: { + url: server.PREFIX, + }, + }); + { + const response = await client.callTool({ + name: 'browser_type', + arguments: { + element: 'textbox', + ref: 'e2', + text: 'Hi!', + slowly: true, + }, + }); + + expect(response).toContainTextContent(`pressSequentially('Hi!');`); + expect(response).toContainTextContent(`- textbox`); + } + const response = await client.callTool({ + name: 'browser_console_messages', + }); + expect(response).toHaveTextContent(/\[LOG\] Key pressed: H Text: /); + expect(response).toHaveTextContent(/\[LOG\] Key pressed: i Text: H/); + expect(response).toHaveTextContent(/\[LOG\] Key pressed: ! Text: Hi/); +}); + +test('browser_type (no submit)', async ({ client, server }) => { + server.setContent('/', ` + + `, 'text/html'); + + { + const response = await client.callTool({ + name: 'browser_navigate', + arguments: { + url: server.PREFIX, + }, + }); + expect(response).toContainTextContent(`- textbox`); + } + { + const response = await client.callTool({ + name: 'browser_type', + arguments: { + element: 'textbox', + ref: 'e2', + text: 'Hi!', + }, + }); + expect(response).toContainTextContent(`fill('Hi!');`); + // Should yield no snapshot. + expect(response).not.toContainTextContent(`- textbox`); + } + { + const response = await client.callTool({ + name: 'browser_console_messages', + }); + expect(response).toHaveTextContent(/\[LOG\] New value: Hi!/); + } +});