mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-10-12 00:25:14 +03:00
Add response.addCode() calls to browser_wait_for tool and update tests
Co-authored-by: pavelfeldman <883973+pavelfeldman@users.noreply.github.com>
This commit is contained in:
@@ -39,7 +39,9 @@ const wait = defineTool({
|
||||
const code: string[] = [];
|
||||
|
||||
if (params.time) {
|
||||
code.push(`await new Promise(f => setTimeout(f, ${params.time!} * 1000));`);
|
||||
const timeCode = `await new Promise(f => setTimeout(f, ${params.time!} * 1000));`;
|
||||
code.push(timeCode);
|
||||
response.addCode(timeCode);
|
||||
await new Promise(f => setTimeout(f, Math.min(30000, params.time! * 1000)));
|
||||
}
|
||||
|
||||
@@ -48,12 +50,16 @@ const wait = defineTool({
|
||||
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
|
||||
|
||||
if (goneLocator) {
|
||||
code.push(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
||||
const goneCode = `await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`;
|
||||
code.push(goneCode);
|
||||
response.addCode(goneCode);
|
||||
await goneLocator.waitFor({ state: 'hidden' });
|
||||
}
|
||||
|
||||
if (locator) {
|
||||
code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
||||
const locatorCode = `await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`;
|
||||
code.push(locatorCode);
|
||||
response.addCode(locatorCode);
|
||||
await locator.waitFor({ state: 'visible' });
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ test('browser_wait_for(text)', async ({ client, server }) => {
|
||||
name: 'browser_wait_for',
|
||||
arguments: { text: 'Text to appear' },
|
||||
})).toHaveResponse({
|
||||
code: `await page.getByText("Text to appear").first().waitFor({ state: 'visible' });`,
|
||||
pageState: expect.stringContaining(`- generic [ref=e3]: Text to appear`),
|
||||
});
|
||||
});
|
||||
@@ -84,6 +85,23 @@ test('browser_wait_for(textGone)', async ({ client, server }) => {
|
||||
name: 'browser_wait_for',
|
||||
arguments: { textGone: 'Text to disappear' },
|
||||
})).toHaveResponse({
|
||||
code: `await page.getByText("Text to disappear").first().waitFor({ state: 'hidden' });`,
|
||||
pageState: expect.stringContaining(`- generic [ref=e3]: Text to appear`),
|
||||
});
|
||||
});
|
||||
|
||||
test('browser_wait_for(time)', async ({ client, server }) => {
|
||||
server.setContent('/', `<body><div>Hello World</div></body>`, 'text/html');
|
||||
|
||||
await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_wait_for',
|
||||
arguments: { time: 1 },
|
||||
})).toHaveResponse({
|
||||
code: `await new Promise(f => setTimeout(f, 1 * 1000));`,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user