|
| 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('should respect --snapshot-mode=full', async ({ startClient, server }) => { |
| 20 | + server.setContent('/', `<button>Button 1</button>`, 'text/html'); |
| 21 | + |
| 22 | + const { client } = await startClient({ |
| 23 | + args: ['--snapshot-mode=full'], |
| 24 | + }); |
| 25 | + |
| 26 | + expect(await client.callTool({ |
| 27 | + name: 'browser_navigate', |
| 28 | + arguments: { |
| 29 | + url: server.PREFIX, |
| 30 | + }, |
| 31 | + })).toHaveResponse({ |
| 32 | + pageState: expect.stringContaining(` |
| 33 | +- button "Button 1" [ref=e2]`), |
| 34 | + }); |
| 35 | + |
| 36 | + expect(await client.callTool({ |
| 37 | + name: 'browser_evaluate', |
| 38 | + arguments: { |
| 39 | + function: `async () => { |
| 40 | + const button2 = document.createElement('button'); |
| 41 | + button2.textContent = 'Button 2'; |
| 42 | + document.body.appendChild(button2); |
| 43 | + }`, |
| 44 | + }, |
| 45 | + })).toHaveResponse({ |
| 46 | + pageState: expect.stringContaining(` |
| 47 | + - button "Button 1" [ref=e2] |
| 48 | + - button "Button 2" [ref=e3]`), |
| 49 | + }); |
| 50 | +}); |
| 51 | + |
| 52 | +test('should respect --snapshot-mode=incremental', async ({ startClient, server }) => { |
| 53 | + server.setContent('/', `<button>Button 1</button>`, 'text/html'); |
| 54 | + |
| 55 | + const { client } = await startClient({ |
| 56 | + args: ['--snapshot-mode=incremental'], |
| 57 | + }); |
| 58 | + |
| 59 | + expect(await client.callTool({ |
| 60 | + name: 'browser_navigate', |
| 61 | + arguments: { |
| 62 | + url: server.PREFIX, |
| 63 | + }, |
| 64 | + })).toHaveResponse({ |
| 65 | + pageState: expect.stringContaining(` |
| 66 | +- button "Button 1" [ref=e2]`), |
| 67 | + }); |
| 68 | + |
| 69 | + expect(await client.callTool({ |
| 70 | + name: 'browser_evaluate', |
| 71 | + arguments: { |
| 72 | + function: `async () => { |
| 73 | + const button2 = document.createElement('button'); |
| 74 | + button2.textContent = 'Button 2'; |
| 75 | + document.body.appendChild(button2); |
| 76 | + }`, |
| 77 | + }, |
| 78 | + })).toHaveResponse({ |
| 79 | + pageState: expect.stringContaining(` |
| 80 | +- <changed> generic [active] [ref=e1]: |
| 81 | + - ref=e2 [unchanged] |
| 82 | + - button \"Button 2\" [ref=e3]`), |
| 83 | + }); |
| 84 | +}); |
| 85 | + |
| 86 | +test('should respect --snapshot-mode=none', async ({ startClient, server }) => { |
| 87 | + server.setContent('/', `<button>Button 1</button>`, 'text/html'); |
| 88 | + |
| 89 | + const { client } = await startClient({ |
| 90 | + args: ['--snapshot-mode=none'], |
| 91 | + }); |
| 92 | + |
| 93 | + expect(await client.callTool({ |
| 94 | + name: 'browser_navigate', |
| 95 | + arguments: { |
| 96 | + url: server.PREFIX, |
| 97 | + }, |
| 98 | + })).toHaveResponse({ |
| 99 | + pageState: undefined |
| 100 | + }); |
| 101 | +}); |
0 commit comments