chore: move state to tab, do not cache snapshot (#730)

This commit is contained in:
Pavel Feldman
2025-07-22 07:53:33 -07:00
committed by GitHub
parent cfcca40b90
commit 468c84eb8f
23 changed files with 291 additions and 355 deletions

View File

@@ -41,7 +41,7 @@ test('cdp server reuse tab', async ({ cdpServer, startClient, server }) => {
element: 'Hello, world!',
ref: 'f0',
},
})).toHaveTextContent(`Error: No current snapshot available. Capture a snapshot or navigate to a new location first.`);
})).toHaveTextContent(`Error: No open pages available. Use the \"browser_navigate\" tool to navigate to a page first.`);
expect(await client.callTool({
name: 'browser_snapshot',

View File

@@ -242,7 +242,7 @@ test('old locator error message', async ({ client, server }) => {
element: 'Button 2',
ref: 'e3',
},
})).toContainTextContent('Ref not found');
})).toContainTextContent('Ref e3 not found in the current page snapshot. Try capturing new snapshot.');
});
test('visibility: hidden > visible should be shown', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/535' } }, async ({ client, server }) => {

View File

@@ -38,7 +38,7 @@ test('browser_file_upload', async ({ client, server }, testInfo) => {
name: 'browser_file_upload',
arguments: { paths: [] },
})).toHaveTextContent(`
The tool "browser_file_upload" can only be used when there is related modal state present.
Error: The tool "browser_file_upload" can only be used when there is related modal state present.
### Modal state
- There is no modal state present
`.trim());
@@ -88,7 +88,7 @@ The tool "browser_file_upload" can only be used when there is related modal stat
},
});
expect(response).toContainTextContent(`Tool "browser_click" does not handle the modal state.
expect(response).toContainTextContent(`Error: Tool "browser_click" does not handle the modal state.
### Modal state
- [File chooser]: can be handled by the "browser_file_upload" tool`);
}

View File

@@ -49,7 +49,7 @@ test('create new tab', async ({ client }) => {
- 0: [] (about:blank)
- 1: (current) [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)
### Current tab
### Page state
- Page URL: data:text/html,<title>Tab one</title><body>Body one</body>
- Page Title: Tab one
- Page Snapshot:
@@ -63,7 +63,7 @@ test('create new tab', async ({ client }) => {
- 1: [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)
- 2: (current) [Tab two] (data:text/html,<title>Tab two</title><body>Body two</body>)
### Current tab
### Page state
- Page URL: data:text/html,<title>Tab two</title><body>Body two</body>
- Page Title: Tab two
- Page Snapshot:
@@ -75,23 +75,21 @@ test('create new tab', async ({ client }) => {
test('select tab', async ({ client }) => {
await createTab(client, 'Tab one', 'Body one');
await createTab(client, 'Tab two', 'Body two');
expect(await client.callTool({
const result = await client.callTool({
name: 'browser_tab_select',
arguments: {
index: 1,
},
})).toHaveTextContent(`
### Ran Playwright code
\`\`\`js
// <internal code to select tab 1>
\`\`\`
});
expect(result).toContainTextContent(`
### Open tabs
- 0: [] (about:blank)
- 1: (current) [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)
- 2: [Tab two] (data:text/html,<title>Tab two</title><body>Body two</body>)
- 2: [Tab two] (data:text/html,<title>Tab two</title><body>Body two</body>)`);
### Current tab
expect(result).toContainTextContent(`
### Page state
- Page URL: data:text/html,<title>Tab one</title><body>Body one</body>
- Page Title: Tab one
- Page Snapshot:
@@ -103,22 +101,20 @@ test('select tab', async ({ client }) => {
test('close tab', async ({ client }) => {
await createTab(client, 'Tab one', 'Body one');
await createTab(client, 'Tab two', 'Body two');
expect(await client.callTool({
const result = await client.callTool({
name: 'browser_tab_close',
arguments: {
index: 2,
},
})).toHaveTextContent(`
### Ran Playwright code
\`\`\`js
// <internal code to close tab 2>
\`\`\`
});
expect(result).toContainTextContent(`
### Open tabs
- 0: [] (about:blank)
- 1: (current) [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)
- 1: (current) [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)`);
### Current tab
expect(result).toContainTextContent(`
### Page state
- Page URL: data:text/html,<title>Tab one</title><body>Body one</body>
- Page Title: Tab one
- Page Snapshot: