|
16 | 16 |
|
17 | 17 | import { test, expect } from './fixtures.js';
|
18 | 18 |
|
19 |
| -// https://github.com/microsoft/playwright/issues/35663 |
20 |
| -test.skip(({ mcpBrowser, mcpHeadless }) => mcpBrowser === 'webkit' && mcpHeadless); |
21 |
| - |
22 | 19 | test('alert dialog', async ({ client, server }) => {
|
23 | 20 | server.setContent('/', `<button onclick="alert('Alert')">Button</button>`, 'text/html');
|
24 | 21 | expect(await client.callTool({
|
@@ -64,8 +61,6 @@ await page.getByRole('button', { name: 'Button' }).click();
|
64 | 61 | });
|
65 | 62 |
|
66 | 63 | test('two alert dialogs', async ({ client, server }) => {
|
67 |
| - test.fixme(true, 'Race between the dialog and ariaSnapshot'); |
68 |
| - |
69 | 64 | server.setContent('/', `
|
70 | 65 | <title>Title</title>
|
71 | 66 | <body>
|
@@ -100,7 +95,18 @@ await page.getByRole('button', { name: 'Button' }).click();
|
100 | 95 | },
|
101 | 96 | });
|
102 | 97 |
|
103 |
| - expect(result).not.toContainTextContent('### Modal state'); |
| 98 | + expect(result).toContainTextContent(` |
| 99 | +### Modal state |
| 100 | +- ["alert" dialog with message "Alert 2"]: can be handled by the "browser_handle_dialog" tool`); |
| 101 | + |
| 102 | + const result2 = await client.callTool({ |
| 103 | + name: 'browser_handle_dialog', |
| 104 | + arguments: { |
| 105 | + accept: true, |
| 106 | + }, |
| 107 | + }); |
| 108 | + |
| 109 | + expect(result2).not.toContainTextContent('### Modal state'); |
104 | 110 | });
|
105 | 111 |
|
106 | 112 | test('confirm dialog (true)', async ({ client, server }) => {
|
@@ -210,3 +216,47 @@ test('prompt dialog', async ({ client, server }) => {
|
210 | 216 | - generic [active] [ref=e1]: Answer
|
211 | 217 | \`\`\``);
|
212 | 218 | });
|
| 219 | + |
| 220 | +test('alert dialog w/ race', async ({ client, server }) => { |
| 221 | + server.setContent('/', `<button onclick="setTimeout(() => alert('Alert'), 100)">Button</button>`, 'text/html'); |
| 222 | + expect(await client.callTool({ |
| 223 | + name: 'browser_navigate', |
| 224 | + arguments: { url: server.PREFIX }, |
| 225 | + })).toContainTextContent('- button "Button" [ref=e2]'); |
| 226 | + |
| 227 | + expect(await client.callTool({ |
| 228 | + name: 'browser_click', |
| 229 | + arguments: { |
| 230 | + element: 'Button', |
| 231 | + ref: 'e2', |
| 232 | + }, |
| 233 | + })).toHaveTextContent(`- Ran Playwright code: |
| 234 | +\`\`\`js |
| 235 | +// Click Button |
| 236 | +await page.getByRole('button', { name: 'Button' }).click(); |
| 237 | +\`\`\` |
| 238 | +
|
| 239 | +### Modal state |
| 240 | +- ["alert" dialog with message "Alert"]: can be handled by the "browser_handle_dialog" tool`); |
| 241 | + |
| 242 | + const result = await client.callTool({ |
| 243 | + name: 'browser_handle_dialog', |
| 244 | + arguments: { |
| 245 | + accept: true, |
| 246 | + }, |
| 247 | + }); |
| 248 | + |
| 249 | + expect(result).not.toContainTextContent('### Modal state'); |
| 250 | + expect(result).toHaveTextContent(`- Ran Playwright code: |
| 251 | +\`\`\`js |
| 252 | +// <internal code to handle "alert" dialog> |
| 253 | +\`\`\` |
| 254 | +
|
| 255 | +- Page URL: ${server.PREFIX} |
| 256 | +- Page Title: |
| 257 | +- Page Snapshot |
| 258 | +\`\`\`yaml |
| 259 | +- button "Button" [active] [ref=e2] |
| 260 | +\`\`\` |
| 261 | +`); |
| 262 | +}); |
0 commit comments