playwright icon indicating copy to clipboard operation
playwright copied to clipboard

Playwright Agent Generator fails to handle new tab scenarios correctly

Open Mr-jing opened this issue 2 months ago • 1 comments

I'm encountering an issue with Playwright Agent when performing UI automation testing involving new tabs:

Scenario: When clicking an "Add/New" button on the original page, the system opens a new tab displaying the operation interface.

Current Problems:

  1. Tab tool inconsistency: The Playwright MCP tab tool occasionally fails, causing the AI to incorrectly use page.goto() on the original page to navigate to the new page's URL
  2. Incorrect code generation: Even when the tab tool works properly, generator_read_log doesn't include code for tab switching, resulting in generated test code that continues executing operations on the original page object

Expected Behavior: The generator should produce code similar to this to handle new tabs correctly:

  const newPagePromise = page.context().waitForEvent('page', { timeout: 1000 });
  await page.getByText('Add').click();
  const newPage = await newPagePromise;

Impact: Currently unable to generate reliable new tab handling code through the generator, requiring manual corrections and reducing the efficiency of automated test development.

Mr-jing avatar Nov 05 '25 07:11 Mr-jing

@pavelfeldman Hi! Questions:

  1. Are there recommended solutions for handling new tab scenarios?
  2. Are there any improvement plans for the Generator in this area?
  3. Are there configuration options to optimize this behavior?

Thank you very much for your guidance! 🙏

Mr-jing avatar Nov 05 '25 07:11 Mr-jing