|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { test, expect } from './fixtures'; |
| 18 | + |
| 19 | +test('browser_run_code', async ({ client, server }) => { |
| 20 | + server.setContent('/', ` |
| 21 | + <button onclick="console.log('Submit')">Submit</button> |
| 22 | + `, 'text/html'); |
| 23 | + await client.callTool({ |
| 24 | + name: 'browser_navigate', |
| 25 | + arguments: { url: server.PREFIX }, |
| 26 | + }); |
| 27 | + |
| 28 | + expect(await client.callTool({ |
| 29 | + name: 'browser_run_code', |
| 30 | + arguments: { |
| 31 | + code: 'await page.getByRole("button", { name: "Submit" }).click()', |
| 32 | + }, |
| 33 | + })).toHaveResponse({ |
| 34 | + code: `await page.getByRole(\"button\", { name: \"Submit\" }).click()`, |
| 35 | + consoleMessages: expect.stringContaining('- [LOG] Submit'), |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +test('browser_run_code block', async ({ client, server }) => { |
| 40 | + server.setContent('/', ` |
| 41 | + <button onclick="console.log('Submit')">Submit</button> |
| 42 | + `, 'text/html'); |
| 43 | + await client.callTool({ |
| 44 | + name: 'browser_navigate', |
| 45 | + arguments: { url: server.PREFIX }, |
| 46 | + }); |
| 47 | + |
| 48 | + expect(await client.callTool({ |
| 49 | + name: 'browser_run_code', |
| 50 | + arguments: { |
| 51 | + code: 'await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();', |
| 52 | + }, |
| 53 | + })).toHaveResponse({ |
| 54 | + code: expect.stringContaining(`await page.getByRole(\"button\", { name: \"Submit\" }).click()`), |
| 55 | + consoleMessages: expect.stringMatching(/\[LOG\] Submit.*\n.*\[LOG\] Submit/), |
| 56 | + }); |
| 57 | +}); |
| 58 | + |
| 59 | +test('browser_run_code no-require', async ({ client, server }) => { |
| 60 | + server.setContent('/', ` |
| 61 | + <button onclick="console.log('Submit')">Submit</button> |
| 62 | + `, 'text/html'); |
| 63 | + await client.callTool({ |
| 64 | + name: 'browser_navigate', |
| 65 | + arguments: { url: server.PREFIX }, |
| 66 | + }); |
| 67 | + |
| 68 | + expect(await client.callTool({ |
| 69 | + name: 'browser_run_code', |
| 70 | + arguments: { |
| 71 | + code: `require('fs');`, |
| 72 | + }, |
| 73 | + })).toHaveResponse({ |
| 74 | + result: expect.stringContaining(`ReferenceError: require is not defined`), |
| 75 | + }); |
| 76 | +}); |
0 commit comments