mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-27 00:52:27 +08:00
chore: refactor tests (#61)
This commit is contained in:
parent
5e200405e5
commit
b477b7c26f
@ -20,196 +20,72 @@ import path from 'node:path';
|
|||||||
import { test, expect } from './fixtures';
|
import { test, expect } from './fixtures';
|
||||||
|
|
||||||
test('test tool list', async ({ server, visionServer }) => {
|
test('test tool list', async ({ server, visionServer }) => {
|
||||||
const list = await server.send({
|
const tools = await server.listTools();
|
||||||
jsonrpc: '2.0',
|
expect(tools.map(t => t.name)).toEqual([
|
||||||
id: 1,
|
'browser_navigate',
|
||||||
method: 'tools/list',
|
'browser_go_back',
|
||||||
});
|
'browser_go_forward',
|
||||||
|
'browser_choose_file',
|
||||||
|
'browser_snapshot',
|
||||||
|
'browser_click',
|
||||||
|
'browser_hover',
|
||||||
|
'browser_type',
|
||||||
|
'browser_select_option',
|
||||||
|
'browser_take_screenshot',
|
||||||
|
'browser_press_key',
|
||||||
|
'browser_wait',
|
||||||
|
'browser_save_as_pdf',
|
||||||
|
'browser_close',
|
||||||
|
]);
|
||||||
|
|
||||||
expect(list).toEqual(expect.objectContaining({
|
const visionTools = await visionServer.listTools();
|
||||||
id: 1,
|
expect(visionTools.map(t => t.name)).toEqual([
|
||||||
result: expect.objectContaining({
|
'browser_navigate',
|
||||||
tools: [
|
'browser_go_back',
|
||||||
expect.objectContaining({
|
'browser_go_forward',
|
||||||
name: 'browser_navigate',
|
'browser_choose_file',
|
||||||
}),
|
'browser_screenshot',
|
||||||
expect.objectContaining({
|
'browser_move_mouse',
|
||||||
name: 'browser_go_back',
|
'browser_click',
|
||||||
}),
|
'browser_drag',
|
||||||
expect.objectContaining({
|
'browser_type',
|
||||||
name: 'browser_go_forward',
|
'browser_press_key',
|
||||||
}),
|
'browser_wait',
|
||||||
expect.objectContaining({
|
'browser_save_as_pdf',
|
||||||
name: 'browser_choose_file',
|
'browser_close',
|
||||||
}),
|
]);
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_snapshot',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_click',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_hover',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_type',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_select_option',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_take_screenshot',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_press_key',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_wait',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_save_as_pdf',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_close',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const visionList = await visionServer.send({
|
|
||||||
jsonrpc: '2.0',
|
|
||||||
id: 1,
|
|
||||||
method: 'tools/list',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(visionList).toEqual(expect.objectContaining({
|
|
||||||
id: 1,
|
|
||||||
result: expect.objectContaining({
|
|
||||||
tools: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_navigate',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_go_back',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_go_forward',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_screenshot',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_move_mouse',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_click',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_drag',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_type',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_press_key',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_wait',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_save_as_pdf',
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
name: 'browser_close',
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test resources list', async ({ server }) => {
|
test('test resources list', async ({ server }) => {
|
||||||
const list = await server.send({
|
expect(await server.listResources()).toEqual([
|
||||||
jsonrpc: '2.0',
|
expect.objectContaining({
|
||||||
id: 2,
|
uri: 'browser://console',
|
||||||
method: 'resources/list',
|
mimeType: 'text/plain',
|
||||||
});
|
|
||||||
|
|
||||||
expect(list).toEqual(expect.objectContaining({
|
|
||||||
id: 2,
|
|
||||||
result: expect.objectContaining({
|
|
||||||
resources: [
|
|
||||||
expect.objectContaining({
|
|
||||||
uri: 'browser://console',
|
|
||||||
mimeType: 'text/plain',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
}));
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test browser_navigate', async ({ server }) => {
|
test('test browser_navigate', async ({ server }) => {
|
||||||
const response = await server.send({
|
expect(await server.callTool('browser_navigate', { url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>' })).toEqual([
|
||||||
jsonrpc: '2.0',
|
`
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response).toEqual(expect.objectContaining({
|
|
||||||
id: 2,
|
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
type: 'text',
|
|
||||||
text: `
|
|
||||||
- Page URL: data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
|
- Page URL: data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
|
||||||
- Page Title: Title
|
- Page Title: Title
|
||||||
- Page Snapshot
|
- Page Snapshot
|
||||||
\`\`\`yaml
|
\`\`\`yaml
|
||||||
- document [ref=s1e2]: Hello, world!
|
- document [ref=s1e2]: Hello, world!
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`,
|
`
|
||||||
}],
|
]);
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test browser_click', async ({ server }) => {
|
test('test browser_click', async ({ server }) => {
|
||||||
await server.send({
|
await server.callTool(
|
||||||
jsonrpc: '2.0',
|
'browser_navigate',
|
||||||
id: 2,
|
{ url: 'data:text/html,<html><title>Title</title><button>Submit</button></html>' }
|
||||||
method: 'tools/call',
|
);
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><button>Submit</button></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await server.send({
|
expect(await server.callTool('browser_click', { element: 'Submit button', ref: 's1e4' })).toEqual([
|
||||||
jsonrpc: '2.0',
|
`\"Submit button\" clicked
|
||||||
id: 3,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_click',
|
|
||||||
arguments: {
|
|
||||||
element: 'Submit button',
|
|
||||||
ref: 's1e4',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response).toEqual(expect.objectContaining({
|
|
||||||
id: 3,
|
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
type: 'text',
|
|
||||||
text: `\"Submit button\" clicked
|
|
||||||
|
|
||||||
- Page URL: data:text/html,<html><title>Title</title><button>Submit</button></html>
|
- Page URL: data:text/html,<html><title>Title</title><button>Submit</button></html>
|
||||||
- Page Title: Title
|
- Page Title: Title
|
||||||
@ -218,112 +94,37 @@ test('test browser_click', async ({ server }) => {
|
|||||||
- document [ref=s2e2]:
|
- document [ref=s2e2]:
|
||||||
- button \"Submit\" [ref=s2e4]
|
- button \"Submit\" [ref=s2e4]
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`,
|
`]);
|
||||||
}],
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test reopen browser', async ({ server }) => {
|
test('test reopen browser', async ({ server }) => {
|
||||||
const response2 = await server.send({
|
await server.callTool(
|
||||||
jsonrpc: '2.0',
|
'browser_navigate',
|
||||||
id: 2,
|
{ url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>' }
|
||||||
method: 'tools/call',
|
);
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response2).toEqual(expect.objectContaining({
|
expect(await server.callTool('browser_close')).toEqual(['Page closed']);
|
||||||
id: 2,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const response3 = await server.send({
|
expect(await server.callTool('browser_navigate', { url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>' })).toEqual([`
|
||||||
jsonrpc: '2.0',
|
|
||||||
id: 3,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_close',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response3).toEqual(expect.objectContaining({
|
|
||||||
id: 3,
|
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
text: 'Page closed',
|
|
||||||
type: 'text',
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const response4 = await server.send({
|
|
||||||
jsonrpc: '2.0',
|
|
||||||
id: 4,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response4).toEqual(expect.objectContaining({
|
|
||||||
id: 4,
|
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
type: 'text',
|
|
||||||
text: `
|
|
||||||
- Page URL: data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
|
- Page URL: data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
|
||||||
- Page Title: Title
|
- Page Title: Title
|
||||||
- Page Snapshot
|
- Page Snapshot
|
||||||
\`\`\`yaml
|
\`\`\`yaml
|
||||||
- document [ref=s1e2]: Hello, world!
|
- document [ref=s1e2]: Hello, world!
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`,
|
`,]);
|
||||||
}],
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test.describe('test browser_select_option', () => {
|
test.describe('test browser_select_option', () => {
|
||||||
test('single option', async ({ server }) => {
|
test('single option', async ({ server }) => {
|
||||||
await server.send({
|
await server.callTool('browser_navigate', {
|
||||||
jsonrpc: '2.0',
|
url: 'data:text/html,<html><title>Title</title><select><option value="foo">Foo</option><option value="bar">Bar</option></select></html>',
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><select><option value="foo">Foo</option><option value="bar">Bar</option></select></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await server.send({
|
const response = await server.callTool('browser_select_option', { element: 'Select', ref: 's1e4', values: ['bar'] });
|
||||||
jsonrpc: '2.0',
|
|
||||||
id: 3,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_select_option',
|
|
||||||
arguments: {
|
|
||||||
element: 'Select',
|
|
||||||
ref: 's1e4',
|
|
||||||
values: ['bar'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response).toEqual(expect.objectContaining({
|
expect(response).toEqual([
|
||||||
id: 3,
|
`Selected option in \"Select\"
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
type: 'text',
|
|
||||||
text: `Selected option in \"Select\"
|
|
||||||
|
|
||||||
- Page URL: data:text/html,<html><title>Title</title><select><option value="foo">Foo</option><option value="bar">Bar</option></select></html>
|
- Page URL: data:text/html,<html><title>Title</title><select><option value="foo">Foo</option><option value="bar">Bar</option></select></html>
|
||||||
- Page Title: Title
|
- Page Title: Title
|
||||||
@ -334,45 +135,18 @@ test.describe('test browser_select_option', () => {
|
|||||||
- option \"Foo\" [ref=s2e5]
|
- option \"Foo\" [ref=s2e5]
|
||||||
- option \"Bar\" [selected] [ref=s2e6]
|
- option \"Bar\" [selected] [ref=s2e6]
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`,
|
`]);
|
||||||
}],
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('multiple option', async ({ server }) => {
|
test('multiple option', async ({ server }) => {
|
||||||
await server.send({
|
await server.callTool('browser_navigate', {
|
||||||
jsonrpc: '2.0',
|
url: 'data:text/html,<html><title>Title</title><select multiple><option value="foo">Foo</option><option value="bar">Bar</option><option value="baz">Baz</option></select></html>',
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><select multiple><option value="foo">Foo</option><option value="bar">Bar</option><option value="baz">Baz</option></select></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await server.send({
|
const response = await server.callTool('browser_select_option', { element: 'Select', ref: 's1e4', values: ['bar', 'baz'] });
|
||||||
jsonrpc: '2.0',
|
|
||||||
id: 3,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_select_option',
|
|
||||||
arguments: {
|
|
||||||
element: 'Select',
|
|
||||||
ref: 's1e4',
|
|
||||||
values: ['bar', 'baz'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response).toEqual(expect.objectContaining({
|
expect(response).toEqual([
|
||||||
id: 3,
|
`Selected option in \"Select\"
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
type: 'text',
|
|
||||||
text: `Selected option in \"Select\"
|
|
||||||
|
|
||||||
- Page URL: data:text/html,<html><title>Title</title><select multiple><option value="foo">Foo</option><option value="bar">Bar</option><option value="baz">Baz</option></select></html>
|
- Page URL: data:text/html,<html><title>Title</title><select multiple><option value="foo">Foo</option><option value="bar">Bar</option><option value="baz">Baz</option></select></html>
|
||||||
- Page Title: Title
|
- Page Title: Title
|
||||||
@ -384,64 +158,27 @@ test.describe('test browser_select_option', () => {
|
|||||||
- option \"Bar\" [selected] [ref=s2e6]
|
- option \"Bar\" [selected] [ref=s2e6]
|
||||||
- option \"Baz\" [selected] [ref=s2e7]
|
- option \"Baz\" [selected] [ref=s2e7]
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`,
|
`]);
|
||||||
}],
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('browser://console', async ({ server }) => {
|
test('browser://console', async ({ server }) => {
|
||||||
await server.send({
|
await server.callTool('browser_navigate', {
|
||||||
jsonrpc: '2.0',
|
url: 'data:text/html,<html><script>console.log("Hello, world!");console.error("Error"); </script></html>',
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><script>console.log("Hello, world!");console.error("Error"); </script></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
expect(await server.readResource('browser://console')).toEqual([{
|
||||||
const response = await server.send({
|
uri: 'browser://console',
|
||||||
jsonrpc: '2.0',
|
mimeType: 'text/plain',
|
||||||
id: 3,
|
text: '[LOG] Hello, world!\n[ERROR] Error',
|
||||||
method: 'resources/read',
|
}]);
|
||||||
params: {
|
|
||||||
uri: 'browser://console',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(response).toEqual(expect.objectContaining({
|
|
||||||
result: expect.objectContaining({
|
|
||||||
contents: [{
|
|
||||||
uri: 'browser://console',
|
|
||||||
mimeType: 'text/plain',
|
|
||||||
text: '[LOG] Hello, world!\n[ERROR] Error',
|
|
||||||
}],
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stitched aria frames', async ({ server }) => {
|
test('stitched aria frames', async ({ server }) => {
|
||||||
const response = await server.send({
|
const response = await server.callTool('browser_navigate', {
|
||||||
jsonrpc: '2.0',
|
url: 'data:text/html,<h1>Hello</h1><iframe src="data:text/html,<h1>World</h1>"></iframe><iframe src="data:text/html,<h1>Should be invisible</h1>" style="display: none;"></iframe>',
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<h1>Hello</h1><iframe src="data:text/html,<h1>World</h1>"></iframe><iframe src="data:text/html,<h1>Should be invisible</h1>" style="display: none;"></iframe>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(response).toEqual(expect.objectContaining({
|
expect(response).toEqual([`
|
||||||
id: 2,
|
|
||||||
result: {
|
|
||||||
content: [{
|
|
||||||
type: 'text',
|
|
||||||
text: `
|
|
||||||
- Page URL: data:text/html,<h1>Hello</h1><iframe src="data:text/html,<h1>World</h1>"></iframe><iframe src="data:text/html,<h1>Should be invisible</h1>" style="display: none;"></iframe>
|
- Page URL: data:text/html,<h1>Hello</h1><iframe src="data:text/html,<h1>World</h1>"></iframe><iframe src="data:text/html,<h1>Should be invisible</h1>" style="display: none;"></iframe>
|
||||||
- Page Title:
|
- Page Title:
|
||||||
- Page Snapshot
|
- Page Snapshot
|
||||||
@ -453,87 +190,47 @@ test('stitched aria frames', async ({ server }) => {
|
|||||||
- document [ref=f0s1e2]:
|
- document [ref=f0s1e2]:
|
||||||
- heading \"World\" [level=1] [ref=f0s1e4]
|
- heading \"World\" [level=1] [ref=f0s1e4]
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`,
|
`
|
||||||
}],
|
]);
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('browser_choose_file', async ({ server }) => {
|
test('browser_choose_file', async ({ server }) => {
|
||||||
let response = await server.send({
|
let response = await server.callTool('browser_navigate', {
|
||||||
jsonrpc: '2.0',
|
url: 'data:text/html,<html><title>Title</title><input type="file" /><button>Button</button></html>',
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'data:text/html,<html><title>Title</title><input type="file" /><button>Button</button></html>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(response.result.content[0].text).toContain('- textbox [ref=s1e4]');
|
expect(response[0]).toContain('- textbox [ref=s1e4]');
|
||||||
|
|
||||||
response = await server.send({
|
response = await server.callTool('browser_click', {
|
||||||
jsonrpc: '2.0',
|
element: 'Textbox',
|
||||||
id: 2,
|
ref: 's1e4',
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_click',
|
|
||||||
arguments: {
|
|
||||||
element: 'Textbox',
|
|
||||||
ref: 's1e4',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(response.result.content[0].text).toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
expect(response[0]).toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
||||||
|
|
||||||
const filePath = test.info().outputPath('test.txt');
|
const filePath = test.info().outputPath('test.txt');
|
||||||
await fs.writeFile(filePath, 'Hello, world!');
|
await fs.writeFile(filePath, 'Hello, world!');
|
||||||
response = await server.send({
|
response = await server.callTool('browser_choose_file', {
|
||||||
jsonrpc: '2.0',
|
paths: [filePath],
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_choose_file',
|
|
||||||
arguments: {
|
|
||||||
paths: [filePath],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(response.result.content[0].text).not.toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
expect(response[0]).not.toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
||||||
expect(response.result.content[0].text).toContain('textbox [ref=s3e4]: C:\\fakepath\\test.txt');
|
expect(response[0]).toContain('textbox [ref=s3e4]: C:\\fakepath\\test.txt');
|
||||||
|
|
||||||
response = await server.send({
|
response = await server.callTool('browser_click', {
|
||||||
jsonrpc: '2.0',
|
element: 'Textbox',
|
||||||
id: 2,
|
ref: 's3e4',
|
||||||
method: 'tools/call',
|
|
||||||
params: {
|
|
||||||
name: 'browser_click',
|
|
||||||
arguments: {
|
|
||||||
element: 'Textbox',
|
|
||||||
ref: 's3e4',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
expect(response.result.content[0].text).toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
|
||||||
expect(response.result.content[0].text).toContain('button "Button" [ref=s4e5]');
|
|
||||||
|
|
||||||
response = await server.send({
|
expect(response[0]).toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
||||||
jsonrpc: '2.0',
|
expect(response[0]).toContain('button "Button" [ref=s4e5]');
|
||||||
id: 2,
|
|
||||||
method: 'tools/call',
|
response = await server.callTool('browser_click', {
|
||||||
params: {
|
element: 'Button',
|
||||||
name: 'browser_click',
|
ref: 's4e5',
|
||||||
arguments: {
|
|
||||||
element: 'Button',
|
|
||||||
ref: 's4e5',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
expect(response.result.content[0].text, 'not submitting browser_choose_file dismisses file chooser').not.toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
|
||||||
|
expect(response[0], 'not submitting browser_choose_file dismisses file chooser').not.toContain('There is a file chooser visible that requires browser_choose_file to be called');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sse transport', async () => {
|
test('sse transport', async () => {
|
||||||
|
@ -108,6 +108,49 @@ class MCPServer extends EventEmitter {
|
|||||||
this._child.stdin?.end();
|
this._child.stdin?.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async listTools() {
|
||||||
|
const list = await this.send({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 0,
|
||||||
|
method: 'tools/list',
|
||||||
|
});
|
||||||
|
return list.result.tools;
|
||||||
|
}
|
||||||
|
|
||||||
|
async listResources() {
|
||||||
|
const list = await this.send({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 0,
|
||||||
|
method: 'resources/list',
|
||||||
|
});
|
||||||
|
return list.result.resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
async callTool(name: string, args?: any) {
|
||||||
|
const result = await this.send({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 0,
|
||||||
|
method: 'tools/call',
|
||||||
|
params: {
|
||||||
|
name,
|
||||||
|
arguments: args,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result.result.content.map(c => c.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
async readResource(uri: string) {
|
||||||
|
const result = await this.send({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 0,
|
||||||
|
method: 'resources/read',
|
||||||
|
params: {
|
||||||
|
uri,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return result.result.contents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Fixtures = {
|
type Fixtures = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user