Playwright Multiple Tabs and Popups Tutorial for Real Browser Flows
Tutorial for Playwright multiple tabs and popup flows, including new pages, tab selection, and stable cross-window assertions.
A lot of test suites stay simplistic until a real user flow opens another tab, payment window, invoice preview, or SSO popup. That is why playwright multiple tabs is such a valuable long-tail query: it shows up exactly when browser automation starts touching production-like behavior.
Key Takeaways
- Wait for the popup or context page event before triggering the action.
- Assert on the new page only after it finishes loading what the scenario actually needs.
- Keep primary-tab and secondary-tab assertions separate so failures point to the right page.
- Use CLI tab commands to inspect real flows during debugging.
Why This Topic Matters in 2026
- Checkout, OAuth, docs portals, report exports, and B2B dashboards frequently open secondary pages.
- Popup handling is where framework gaps often show up, so Playwright teams want patterns that stay stable.
- The Playwright CLI is useful for this class of issue because it lets you inspect and switch tabs quickly while reproducing the behavior manually.
Practical Workflow
Step 1: Capture the popup event before the click
If you wait for the page after the click, you can miss the event in fast environments. Always start waiting first.
const popupPromise = page.waitForEvent('popup');
await page.getByRole('link', { name: 'Open invoice preview' }).click();
const popup = await popupPromise;
await popup.waitForLoadState('domcontentloaded');
Step 2: Differentiate new tabs from context-level new pages
Popups spawned from the current page can be captured from the page. Brand-new tabs created elsewhere in the context are easier to observe at the context level.
const pagePromise = context.waitForEvent('page');
await page.getByRole('button', { name: 'Open support center' }).click();
const supportPage = await pagePromise;
await expect(supportPage).toHaveURL(/support/);
Step 3: Mirror the same debugging flow in the CLI
When the test fails only in a real environment, reproduce it quickly with tabs and snapshots before you change test code.
playwright-cli open https://example.com
playwright-cli tab-new https://example.com/invoice
playwright-cli tab-list
playwright-cli tab-select 1
playwright-cli snapshot
Where the Playwright CLI Skill Fits
This is exactly where Playwright CLI Browser Automation adds value. The skill gives your agent stable guidance for snapshots, uploads, downloads, tab handling, tracing, screenshots, PDFs, and fast browser investigation without forcing you to reinvent the command flow every time.
If you are building out a broader QA workflow, keep the skill installed and pair it with the wider QASkills.sh skills directory catalog so your agent can switch between browser automation, API testing, CI, accessibility, and reporting with less context loss.
Common Mistakes to Avoid
- Clicking first and waiting second, which causes intermittent missed popup events.
- Assuming every second window is a popup when some flows create full context pages instead.
- Asserting only on URL and skipping visible content checks inside the new tab.
- Keeping all tab logic in one huge test block that is hard to debug when the wrong page is active.
Related Reading on QASkills.sh
Conclusion
Multi-tab automation stops being difficult once the event order is explicit. Wait first, scope assertions to the right page, and use the CLI when you need fast browser-level visibility into tab behavior.