16. Browser, Context & Page Hierarchy

The Playwright Hierarchy

1. Playwright: The top-level connection to the driver. 2. Browser: The browser process (Chromium, Firefox, WebKit). 3. BrowserContext: An incognito profile with separate cookies, cache, and localStorage. 4. Page: A single browser tab or window.
try (Playwright playwright = Playwright.create()) {
    Browser browser = playwright.chromium().launch();
    BrowserContext context = browser.newContext();
    Page page = context.newPage();
    page.navigate("https://targetqa.com");
}

Task

  • Create a helper method countOpenPages:
  • 1. Accept BrowserContext context.
  • 2. Return context.pages().size().
πŸ’‘Common doubts
Did you like the problem?
Lesson 16 of 38
Java
Loading code editor…
Next