Advanced Playwright and AI in Playwright

Advanced Playwright and AI is the eighth and last chapter of the free Playwright tutorial. It looks beyond the test runner and ends with a reference page for the whole course.

What each lesson covers:

  • Playwright Library and Advanced Browser Control: Automation scripts with the Playwright Library, launch options and persistent profiles, fake time with page.clock, and running your own code in the page with evaluate, addInitScript and exposeFunction.
  • AI-Assisted Testing with Agents, MCP, and CLI: How AI agents see pages, the Playwright MCP server, playwright-cli, the planner, generator and healer test agents, and how to review tests an AI wrote.
  • Capstone: Test the Practice Shop: Build a complete suite step by step, with a CI-ready config, a saved login, page objects, fixtures, end-to-end journeys, API data, mocked failures, an accessibility gate and a traced failure.
  • Playwright Cheat Sheet: Commands, locators, actions, assertions, config, fixtures, authentication, network, API, debugging, reporting and CI on one page, with review exercises.

Every test box runs in the Playwright lab in your browser, in TypeScript or JavaScript. Terminal boxes simulate the AI tools' commands.

Lessons in this section

  1. Playwright Library and Advanced Browser Control

    Playwright Test versus the Playwright Library, writing automation scripts with chromium.launch(), launch options, persistent contexts and connecting to running browsers, PDFs and full-page screenshots, controlling time with page.clock, running code in the page with evaluate, addInitScript and exposeFunction, waiting for page conditions with waitForFunction, and CDP sessions.

    • Explain when to use the Playwright Library instead of Playwright Test
    • Write an automation script with launch, context, page and close
    • Control time in the page with page.clock
    • Run code in the page with evaluate, addInitScript and exposeFunction
  2. AI-Assisted Testing with Agents, MCP, and CLI

    How AI coding agents work with Playwright, accessibility snapshots as the agent's view of a page, the Playwright MCP server, playwright-cli for coding agents, Playwright Test Agents (planner, generator and healer) with init-agents and seed tests, reviewing AI-written tests for weak locators, fixed waits and missing checks, and safe habits when agents drive browsers.

    • Explain how AI agents see and control a page through accessibility snapshots
    • Connect a coding agent to Playwright with MCP or playwright-cli
    • Set up Playwright Test Agents with init-agents and a seed test
    • Review AI-written tests and fix weak locators, fixed waits and missing checks
  3. Capstone: Test the Practice Shop

    Build a complete Playwright suite for the Practice Shop step by step: risk-based planning, a CI-ready config with a setup project, a saved login, page objects, fixtures with option data, end-to-end journeys with unhappy paths, API-powered test data, mocked failure states, an accessibility gate, investigating a failure with a trace, and shipping the suite to CI.

    • Plan a test suite from business risks
    • Combine config, setup projects, page objects and fixtures in one project
    • Write end-to-end journeys that include unhappy paths
    • Use the API for test data and mocks for failure states
  4. Playwright Cheat Sheet

    A one-page reference for the whole course: CLI commands, test structure, locators, actions, assertions, configuration, fixtures, authentication, network mocking, API testing, debugging, reporting and CI, with runnable examples and three review exercises.

    • Find the right Playwright command or API quickly
    • Recall the best-practice choice for locators, waits and assertions
    • Combine UI, network and API features in one test