15. Browser, BrowserContext & Page Hierarchy

Context Isolation Pattern

with sync_playwright() as p:
    browser = p.chromium.launch()

admin_context = browser.new_context()
admin_page = admin_context.new_page()
admin_page.goto("https://targetqa.com/admin")

customer_context = browser.new_context()
customer_page = customer_context.new_page()
customer_page.goto("https://targetqa.com/store")

browser.close()

Task

  • Implement count_open_pages(context):
  • 1. Return len(context.pages) if context else 0.
πŸ’‘Common doubts
Did you like the problem?
Lesson 15 of 37
Python
Loading code editor…
Next