feat(tool): add locator.selectOption() action (#25)

Implemented `locator.selectOption`
This commit is contained in:
ryo kishida
2025-03-26 13:53:56 +09:00
committed by GitHub
parent 8f3214a06a
commit 9f93af3a81
4 changed files with 132 additions and 0 deletions

View File

@@ -48,6 +48,9 @@ test('test tool list', async ({ server }) => {
expect.objectContaining({
name: 'browser_type',
}),
expect.objectContaining({
name: 'browser_select_option',
}),
expect.objectContaining({
name: 'browser_press_key',
}),
@@ -227,3 +230,104 @@ test('test reopen browser', async ({ server }) => {
},
}));
});
test.describe('test browser_select_option', () => {
test('single option', async ({ server }) => {
await server.send({
jsonrpc: '2.0',
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({
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({
id: 3,
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 Title: Title
- Page Snapshot
\`\`\`yaml
- document [ref=s2e2]:
- combobox [ref=s2e4]:
- option \"Foo\" [ref=s2e5]
- option \"Bar\" [selected] [ref=s2e6]
\`\`\`
`,
}],
},
}));
});
test('multiple option', async ({ server }) => {
await server.send({
jsonrpc: '2.0',
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({
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({
id: 3,
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 Title: Title
- Page Snapshot
\`\`\`yaml
- document [ref=s2e2]:
- listbox [ref=s2e4]:
- option \"Foo\" [ref=s2e5]
- option \"Bar\" [selected] [ref=s2e6]
- option \"Baz\" [selected] [ref=s2e7]
\`\`\`
`,
}],
},
}));
});
});