Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: clean up tool example (#34512)

Pavel Feldmanab01dccf9dbe
diff --git a/packages/playwright-tools/src/examples/browser-openai.ts b/packages/playwright-tools/src/examples/browser-openai.ts
index 3d39618f5b..3542d4ba1d 100644
--- a/packages/playwright-tools/src/examples/browser-openai.ts
+++ b/packages/playwright-tools/src/examples/browser-openai.ts
@@ -91,11 +91,10 @@ async function openAIAgentLoop(page: playwright.Page, task: string) {
model: 'gpt-4o',
messages: toOpenAIMessages(history),
tools,
+ tool_choice: 'required',
store: true,
});
- console.log(JSON.stringify(completion, null, 2));
-
const toolCalls = completion.choices[0]?.message?.tool_calls;
if (!toolCalls || toolCalls.length !== 1 || toolCalls[0].type !== 'function') {
history.push({ role: 'user', content: 'expected exactly one tool call', history: 'expected exactly one tool call' });
@@ -113,7 +112,6 @@ async function openAIAgentLoop(page: playwright.Page, task: string) {
// Run the Playwright tool.
const params = JSON.parse(toolCall.function.arguments);
const { error, snapshot, code } = await browser.call(page, toolCall.function.name, params);
- console.log({ error, code, snapshot });
if (code.length)
console.log(code.join('\n'));
@@ -149,9 +147,6 @@ async function main() {
- Go to http://github.com/microsoft
- Search for "playwright" repository
- Navigate to it
- - Capture snapshot for toolbar with Code, Issues, etc.
- - Capture snapshot for branch selector
- - Assert that number of Issues is present
- Switch into the Issues tab
- Report 3 first issues
`);
diff --git a/packages/playwright-tools/src/tools/browser.ts b/packages/playwright-tools/src/tools/browser.ts
index 267d03bcb3..4b63487942 100644
--- a/packages/playwright-tools/src/tools/browser.ts
+++ b/packages/playwright-tools/src/tools/browser.ts
@@ -126,6 +126,8 @@ async function performAction(page: playwright.Page, toolName: string, params: Re
if (toolName === 'navigate') {
code.push(`await page.goto(${JSON.stringify(params.url)})`);
await page.goto(params.url as string);
+ } else if (toolName === 'wait') {
+ await page.waitForTimeout(Math.min(10000, params.time as number * 1000));
} else if (toolName === 'click') {
code.push(`await page.${await locator._generateLocatorString()}.click()`);
await locator.click();