mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2026-01-31 20:03:39 +00:00
chore: parse response in tests (#796)
This commit is contained in:
@@ -21,7 +21,9 @@ test('alert dialog', async ({ client, server }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
})).toContainTextContent('- button "Button" [ref=e2]');
|
||||
})).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
@@ -29,25 +31,31 @@ test('alert dialog', async ({ client, server }) => {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toHaveTextContent(`### Ran Playwright code
|
||||
\`\`\`js
|
||||
// Click Button
|
||||
await page.getByRole('button', { name: 'Button' }).click();
|
||||
\`\`\`
|
||||
})).toHaveResponse({
|
||||
code: `await page.getByRole('button', { name: 'Button' }).click();`,
|
||||
modalState: `- ["alert" dialog with message "Alert"]: can be handled by the "browser_handle_dialog" tool`,
|
||||
});
|
||||
|
||||
### Modal state
|
||||
- ["alert" dialog with message "Alert"]: can be handled by the "browser_handle_dialog" tool
|
||||
`);
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
arguments: {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toHaveResponse({
|
||||
code: undefined,
|
||||
modalState: `- ["alert" dialog with message "Alert"]: can be handled by the "browser_handle_dialog" tool`,
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
expect(await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
arguments: {
|
||||
accept: true,
|
||||
},
|
||||
})).toHaveResponse({
|
||||
modalState: undefined,
|
||||
pageState: expect.stringContaining(`- button "Button"`),
|
||||
});
|
||||
|
||||
expect(result).not.toContainTextContent('### Modal state');
|
||||
expect(result).toContainTextContent(`Page Snapshot:`);
|
||||
});
|
||||
|
||||
test('two alert dialogs', async ({ client, server }) => {
|
||||
@@ -61,7 +69,9 @@ test('two alert dialogs', async ({ client, server }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
})).toContainTextContent('- button "Button" [ref=e2]');
|
||||
})).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
@@ -69,15 +79,10 @@ test('two alert dialogs', async ({ client, server }) => {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toHaveTextContent(`### Ran Playwright code
|
||||
\`\`\`js
|
||||
// Click Button
|
||||
await page.getByRole('button', { name: 'Button' }).click();
|
||||
\`\`\`
|
||||
|
||||
### Modal state
|
||||
- ["alert" dialog with message "Alert 1"]: can be handled by the "browser_handle_dialog" tool
|
||||
`);
|
||||
})).toHaveResponse({
|
||||
code: `await page.getByRole('button', { name: 'Button' }).click();`,
|
||||
modalState: expect.stringContaining(`- ["alert" dialog with message "Alert 1"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
@@ -86,9 +91,9 @@ await page.getByRole('button', { name: 'Button' }).click();
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toContainTextContent(`### Modal state
|
||||
- ["alert" dialog with message "Alert 2"]: can be handled by the "browser_handle_dialog" tool
|
||||
`);
|
||||
expect(result).toHaveResponse({
|
||||
modalState: expect.stringContaining(`- ["alert" dialog with message "Alert 2"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
|
||||
const result2 = await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
@@ -97,7 +102,9 @@ await page.getByRole('button', { name: 'Button' }).click();
|
||||
},
|
||||
});
|
||||
|
||||
expect(result2).not.toContainTextContent('### Modal state');
|
||||
expect(result2).not.toHaveResponse({
|
||||
modalState: expect.stringContaining(`- ["alert" dialog with message "Alert 2"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
});
|
||||
|
||||
test('confirm dialog (true)', async ({ client, server }) => {
|
||||
@@ -111,7 +118,9 @@ test('confirm dialog (true)', async ({ client, server }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
})).toContainTextContent('- button "Button" [ref=e2]');
|
||||
})).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
@@ -119,21 +128,19 @@ test('confirm dialog (true)', async ({ client, server }) => {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toContainTextContent(`### Modal state
|
||||
- ["confirm" dialog with message "Confirm"]: can be handled by the "browser_handle_dialog" tool`);
|
||||
})).toHaveResponse({
|
||||
modalState: expect.stringContaining(`- ["confirm" dialog with message "Confirm"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
expect(await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
arguments: {
|
||||
accept: true,
|
||||
},
|
||||
})).toHaveResponse({
|
||||
modalState: undefined,
|
||||
pageState: expect.stringContaining(`- generic [active] [ref=e1]: "true"`),
|
||||
});
|
||||
|
||||
expect(result).not.toContainTextContent('### Modal state');
|
||||
expect(result).toContainTextContent(`- Page Snapshot:
|
||||
\`\`\`yaml
|
||||
- generic [active] [ref=e1]: "true"
|
||||
\`\`\``);
|
||||
});
|
||||
|
||||
test('confirm dialog (false)', async ({ client, server }) => {
|
||||
@@ -147,7 +154,9 @@ test('confirm dialog (false)', async ({ client, server }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
})).toContainTextContent('- button "Button" [ref=e2]');
|
||||
})).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
@@ -155,21 +164,19 @@ test('confirm dialog (false)', async ({ client, server }) => {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toContainTextContent(`### Modal state
|
||||
- ["confirm" dialog with message "Confirm"]: can be handled by the "browser_handle_dialog" tool
|
||||
`);
|
||||
})).toHaveResponse({
|
||||
modalState: expect.stringContaining(`- ["confirm" dialog with message "Confirm"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
expect(await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
arguments: {
|
||||
accept: false,
|
||||
},
|
||||
})).toHaveResponse({
|
||||
modalState: undefined,
|
||||
pageState: expect.stringContaining(`- generic [active] [ref=e1]: "false"`),
|
||||
});
|
||||
|
||||
expect(result).toContainTextContent(`- Page Snapshot:
|
||||
\`\`\`yaml
|
||||
- generic [active] [ref=e1]: "false"
|
||||
\`\`\``);
|
||||
});
|
||||
|
||||
test('prompt dialog', async ({ client, server }) => {
|
||||
@@ -183,7 +190,9 @@ test('prompt dialog', async ({ client, server }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
})).toContainTextContent('- button "Button" [ref=e2]');
|
||||
})).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
@@ -191,9 +200,9 @@ test('prompt dialog', async ({ client, server }) => {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toContainTextContent(`### Modal state
|
||||
- ["prompt" dialog with message "Prompt"]: can be handled by the "browser_handle_dialog" tool
|
||||
`);
|
||||
})).toHaveResponse({
|
||||
modalState: expect.stringContaining(`- ["prompt" dialog with message "Prompt"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
@@ -203,10 +212,9 @@ test('prompt dialog', async ({ client, server }) => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toContainTextContent(`- Page Snapshot:
|
||||
\`\`\`yaml
|
||||
- generic [active] [ref=e1]: Answer
|
||||
\`\`\``);
|
||||
expect(result).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- generic [active] [ref=e1]: Answer`),
|
||||
});
|
||||
});
|
||||
|
||||
test('alert dialog w/ race', async ({ client, server }) => {
|
||||
@@ -214,7 +222,9 @@ test('alert dialog w/ race', async ({ client, server }) => {
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: { url: server.PREFIX },
|
||||
})).toContainTextContent('- button "Button" [ref=e2]');
|
||||
})).toHaveResponse({
|
||||
pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
|
||||
});
|
||||
|
||||
expect(await client.callTool({
|
||||
name: 'browser_click',
|
||||
@@ -222,15 +232,10 @@ test('alert dialog w/ race', async ({ client, server }) => {
|
||||
element: 'Button',
|
||||
ref: 'e2',
|
||||
},
|
||||
})).toHaveTextContent(`### Ran Playwright code
|
||||
\`\`\`js
|
||||
// Click Button
|
||||
await page.getByRole('button', { name: 'Button' }).click();
|
||||
\`\`\`
|
||||
|
||||
### Modal state
|
||||
- ["alert" dialog with message "Alert"]: can be handled by the "browser_handle_dialog" tool
|
||||
`);
|
||||
})).toHaveResponse({
|
||||
code: `await page.getByRole('button', { name: 'Button' }).click();`,
|
||||
modalState: expect.stringContaining(`- ["alert" dialog with message "Alert"]: can be handled by the "browser_handle_dialog" tool`),
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
name: 'browser_handle_dialog',
|
||||
@@ -239,11 +244,12 @@ await page.getByRole('button', { name: 'Button' }).click();
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).not.toContainTextContent('### Modal state');
|
||||
expect(result).toContainTextContent(`### Page state
|
||||
- Page URL: ${server.PREFIX}
|
||||
expect(result).toHaveResponse({
|
||||
modalState: undefined,
|
||||
pageState: expect.stringContaining(`- Page URL: ${server.PREFIX}
|
||||
- Page Title:
|
||||
- Page Snapshot:
|
||||
\`\`\`yaml
|
||||
- button "Button"`);
|
||||
- button "Button"`),
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user