-
Notifications
You must be signed in to change notification settings - Fork 2.2k
chore: resolve dialog races #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,6 @@ | |
|
|
||
| import { test, expect } from './fixtures.js'; | ||
|
|
||
| // https://github.com/microsoft/playwright/issues/35663 | ||
| test.skip(({ mcpBrowser, mcpHeadless }) => mcpBrowser === 'webkit' && mcpHeadless); | ||
|
|
||
| test('alert dialog', async ({ client, server }) => { | ||
| server.setContent('/', `<button onclick="alert('Alert')">Button</button>`, 'text/html'); | ||
| expect(await client.callTool({ | ||
|
|
@@ -49,7 +46,7 @@ await page.getByRole('button', { name: 'Button' }).click(); | |
| }); | ||
|
|
||
| expect(result).not.toContainTextContent('### Modal state'); | ||
| expect(result).toHaveTextContent(`- Ran Playwright code: | ||
| expect(result).toContainTextContent(`- Ran Playwright code: | ||
| \`\`\`js | ||
| // <internal code to handle "alert" dialog> | ||
| \`\`\` | ||
|
|
@@ -58,14 +55,10 @@ await page.getByRole('button', { name: 'Button' }).click(); | |
| - Page Title: | ||
| - Page Snapshot | ||
| \`\`\`yaml | ||
| - button "Button" [active] [ref=e2] | ||
| \`\`\` | ||
| `); | ||
| - button "Button"`); | ||
| }); | ||
|
|
||
| test('two alert dialogs', async ({ client, server }) => { | ||
| test.fixme(true, 'Race between the dialog and ariaSnapshot'); | ||
|
|
||
| server.setContent('/', ` | ||
| <title>Title</title> | ||
| <body> | ||
|
|
@@ -100,7 +93,18 @@ await page.getByRole('button', { name: 'Button' }).click(); | |
| }, | ||
| }); | ||
|
|
||
| expect(result).not.toContainTextContent('### Modal state'); | ||
| expect(result).toContainTextContent(` | ||
| ### Modal state | ||
| - ["alert" dialog with message "Alert 2"]: can be handled by the "browser_handle_dialog" tool`); | ||
|
|
||
| const result2 = await client.callTool({ | ||
| name: 'browser_handle_dialog', | ||
| arguments: { | ||
| accept: true, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result2).not.toContainTextContent('### Modal state'); | ||
| }); | ||
|
|
||
| test('confirm dialog (true)', async ({ client, server }) => { | ||
|
|
@@ -210,3 +214,45 @@ test('prompt dialog', async ({ client, server }) => { | |
| - generic [active] [ref=e1]: Answer | ||
| \`\`\``); | ||
| }); | ||
|
|
||
| test('alert dialog w/ race', async ({ client, server }) => { | ||
| server.setContent('/', `<button onclick="setTimeout(() => alert('Alert'), 100)">Button</button>`, 'text/html'); | ||
| expect(await client.callTool({ | ||
| name: 'browser_navigate', | ||
| arguments: { url: server.PREFIX }, | ||
| })).toContainTextContent('- button "Button" [ref=e2]'); | ||
|
|
||
| expect(await client.callTool({ | ||
| name: 'browser_click', | ||
| arguments: { | ||
| element: 'Button', | ||
| ref: 'e2', | ||
| }, | ||
| })).toHaveTextContent(`- Ran Playwright code: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear why this test would work. Click will return immediately, snapshot will be empty. Then the dialog will appear.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /s
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are asking the question that you yourself answered :P |
||
| \`\`\`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`); | ||
|
|
||
| const result = await client.callTool({ | ||
| name: 'browser_handle_dialog', | ||
| arguments: { | ||
| accept: true, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).not.toContainTextContent('### Modal state'); | ||
| expect(result).toContainTextContent(`- Ran Playwright code: | ||
| \`\`\`js | ||
| // <internal code to handle "alert" dialog> | ||
| \`\`\` | ||
|
|
||
| - Page URL: ${server.PREFIX} | ||
| - Page Title: | ||
| - Page Snapshot | ||
| \`\`\`yaml | ||
| - button "Button"`); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks the same as #598, did something change?