feat: respond with action and generated locator (#181)

Closes https://github.com/microsoft/playwright-mcp/issues/163
This commit is contained in:
Simon Knott
2025-04-15 19:55:20 +02:00
committed by GitHub
parent 4d59e06184
commit 4a19e18999
10 changed files with 126 additions and 52 deletions

View File

@@ -26,6 +26,8 @@ test('browser_navigate', async ({ client }) => {
})).toHaveTextContent(`
Navigated to data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
- Action: await page.goto('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 Snapshot
@@ -50,7 +52,10 @@ test('browser_click', async ({ client }) => {
element: 'Submit button',
ref: 's1e3',
},
})).toHaveTextContent(`Clicked "Submit button"
})).toHaveTextContent(`
Clicked "Submit button"
- Action: await page.getByRole('button', { name: 'Submit' }).click();
- Page URL: data:text/html,<html><title>Title</title><button>Submit</button></html>
- Page Title: Title
@@ -77,7 +82,10 @@ test('browser_select_option', async ({ client }) => {
ref: 's1e3',
values: ['bar'],
},
})).toHaveTextContent(`Selected option in "Select"
})).toHaveTextContent(`
Selected option in "Select"
- Action: await page.getByRole('combobox').selectOption(['bar']);
- 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
@@ -105,7 +113,10 @@ test('browser_select_option (multiple)', async ({ client }) => {
ref: 's1e3',
values: ['bar', 'baz'],
},
})).toHaveTextContent(`Selected option in "Select"
})).toHaveTextContent(`
Selected option in "Select"
- Action: await page.getByRole('listbox').selectOption(['bar', 'baz']);
- 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

View File

@@ -23,17 +23,7 @@ test('cdp server', async ({ cdpEndpoint, startClient }) => {
arguments: {
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
},
})).toHaveTextContent(`
Navigated to 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 Snapshot
\`\`\`yaml
- text: Hello, world!
\`\`\`
`
);
})).toContainTextContent(`- text: Hello, world!`);
});
test('cdp server reuse tab', async ({ cdpEndpoint, startClient }) => {

View File

@@ -33,16 +33,7 @@ test('test reopen browser', async ({ client }) => {
arguments: {
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
},
})).toHaveTextContent(`
Navigated to 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 Snapshot
\`\`\`yaml
- text: Hello, world!
\`\`\`
`);
})).toContainTextContent(`- text: Hello, world!`);
});
test('executable path', async ({ startClient }) => {

View File

@@ -36,17 +36,7 @@ test('save as pdf', async ({ client }) => {
arguments: {
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
},
})).toHaveTextContent(`
Navigated to 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 Snapshot
\`\`\`yaml
- text: Hello, world!
\`\`\`
`
);
})).toContainTextContent(`- text: Hello, world!`);
const response = await client.callTool({
name: 'browser_pdf_save',