Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/playwright-core/src/tools/backend/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const wait = defineTool({

if (goneLocator) {
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
await goneLocator.waitFor({ state: 'hidden' });
await goneLocator.waitFor({ state: 'hidden', ...tab.actionTimeoutOptions });
}

if (locator) {
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
await locator.waitFor({ state: 'visible' });
await locator.waitFor({ state: 'visible', ...tab.actionTimeoutOptions });
}

response.addTextResult(`Waited for ${params.text || params.textGone || params.time}`);
Expand Down
50 changes: 50 additions & 0 deletions tests/mcp/timeouts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,56 @@ test('action timeout (custom)', async ({ startClient, server }) => {
});
});

test('wait_for text timeout', async ({ startClient, server }) => {
const { client } = await startClient({ args: [`--timeout-action=1234`] });
server.setContent('/', `
<!DOCTYPE html>
<html>
<div>Hello World</div>
</html>
`, 'text/html');

await client.callTool({
name: 'browser_navigate',
arguments: {
url: server.PREFIX,
},
});

expect(await client.callTool({
name: 'browser_wait_for',
arguments: { text: 'This text will never appear' },
})).toHaveResponse({
error: expect.stringContaining(`Timeout 1234ms exceeded.`),
isError: true,
});
});

test('wait_for textGone timeout', async ({ startClient, server }) => {
const { client } = await startClient({ args: [`--timeout-action=1234`] });
server.setContent('/', `
<!DOCTYPE html>
<html>
<div>Permanent text</div>
</html>
`, 'text/html');

await client.callTool({
name: 'browser_navigate',
arguments: {
url: server.PREFIX,
},
});

expect(await client.callTool({
name: 'browser_wait_for',
arguments: { textGone: 'Permanent text' },
})).toHaveResponse({
error: expect.stringContaining(`Timeout 1234ms exceeded.`),
isError: true,
});
});

test('navigation timeout', async ({ startClient, server }) => {
const { client } = await startClient({ args: [`--timeout-navigation=1234`] });
server.setRoute('/slow', async () => {
Expand Down
Loading