Playwright + JS · Lesson 16 of 35

0/35 done

Module 16: Browser, Context & Page

16. Browser, Context and Page Architecture

16 minlesson

Try it yourself

Implement getContextConfig:

  1. Accept width and height numbers.
  2. Return { viewport: { width, height }, permissions: ["geolocation"] }.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

Multi-User Context Testing

javascript
import { test } from "@playwright/test";

test("multi-user chat between Buyer and Support", async ({ browser }) => {
  // Session 1: Buyer
  const buyerContext = await browser.newContext();
  const buyerPage = await buyerContext.newPage();
  await buyerPage.goto("/chat");
  await buyerPage.fill("#message", "I need assistance");
  await buyerPage.click("#send");

  // Session 2: Support agent (isolated cookies and storage)
  const agentContext = await browser.newContext();
  const agentPage = await agentContext.newPage();
  await agentPage.goto("/support");
  await agentPage.getByText("I need assistance").waitFor();

  await buyerContext.close();
  await agentContext.close();
});

Key Takeaways & Walkthrough Summary

Playwright's BrowserContext architecture allows you to create completely isolated incognito profiles in milliseconds. In this lesson, we explore browser contexts, page tabs, permissions, and multi-user session testing in JavaScript. Let's take a look!

Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why not launch a new Browser process for each test?

A new browser process takes several seconds and hundreds of megabytes of RAM. A BrowserContext takes under 20 milliseconds and guarantees 100% cookie and storage isolation.

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

JavaScript
Skip