Skip to content
CodeKruPro

MCP or CLI: how an agent should drive the browser

35/99

Module · Agents in the browser: Playwright MCP and test agents

intermediate

about 40 min

What this lesson teaches

The idea

An agent can drive a browser through MCP tools, which send the whole page after every action, or through the Playwright CLI, which saves pages to files and reads them only when needed.

Why a tester cares

The right choice depends on where the agent runs and how often it needs to see the page, and the difference in cost is large.

Words you will meet

CLI:
a command-line tool, run by typing commands in a terminal.
Snapshot:
a text copy of the page's elements at one moment.

What you will do

  1. 1Run the task with MCP
  2. 2Run it with the CLI
  3. 3Compare
  4. 4Choose for six scenarios
Jump to practice

There are two common ways to let an agent drive a browser. MCP tools return the page's snapshot after every action, so the agent always sees the page, and pays for it in context. The Playwright CLI (playwright-cli) is a command-line tool built for coding agents: it saves snapshots to files and replies with a short line, so the agent reads a snapshot only when it needs one. That needs a shell and a file system, which coding agents have and chat assistants often do not.

Both consoles below drive the same simulated ShopLab. Run the same task in each and compare.

Your task

  1. In each console, buy two notebooks and one coffee mug with SAVE10.
  2. Record each run's number of calls and total characters read.
  3. For six scenarios, choose MCP or CLI.

Sign in to practise

The lesson is free to read. A free account lets you talk to the practice bots, run your code and save your score. You will come back to this lesson.

1

MCP tools

No messages yet. Start with a suggested question below.

2

Playwright CLI

No messages yet. Start with a suggested question below.

3

Your answer

How this is checked: When you submit, the server counts the calls in your own MCP tools console log and compares that with your number.

4

Your answer

How this is checked: When you submit, the server adds up the character counts in your own MCP tools console log; within 5% passes.

5

Your answer

How this is checked: When you submit, the server counts the calls in your own Playwright CLI console log and compares that with your number.

6

Your answer

How this is checked: When you submit, the server adds up the character counts in your own Playwright CLI console log; within 5% passes.

7

Label each one

Which suits each scenario better?

0 of 6 labelled

  1. 1A coding agent in a repository writes and runs a Playwright suite.
  2. 2A chat assistant with no shell or file access checks one page for a user.
  3. 3An exploratory session across forty pages, where context budget is the limit.
  4. 4An agent without file access fills a long form and must see the page after each field.
  5. 5A CI job reproduces a bug from a ticket and keeps snapshots as build artefacts.
  6. 6A manual tester drives the browser step by step through an AI chat app.

How this is checked: Each row has a right label. At least 5 of 6 must match. This is a harder check: it earns the second 50 points once the core checks pass.

Core checks earn 50 points and the harder checks the other 50. You can submit as many times as you like.

About this lesson

Playwright MCP vs Playwright CLI for agents: context cost and when to use each

AI Testing for QA EngineersIntermediateAgents in the browser: Playwright MCP and test agents

How it works

There are two common ways for an agent to drive a browser. MCP tools return the full snapshot after every action, so the agent always sees the page and pays for it in context. The Playwright CLI saves snapshots to files and replies with a short line, so the agent reads a snapshot only when it needs one.

The CLI needs a shell and a file system, which coding agents have and chat assistants often do not. The right choice depends on the environment and on how often the agent needs to see the page.

About the assignment

Run the same purchase task in an MCP console and a CLI console, record calls and characters read in each, and choose a driver for six scenarios.

What you will do

  1. Complete the task in the MCP console and note its totals.
  2. Complete it again with the CLI, reading snapshot files only when needed.
  3. For each scenario, ask whether the agent has a shell and how often it must see the page.

Common mistakes

  • Comparing different tasks

    The comparison only means something when both runs do the same thing.

  • Choosing the CLI everywhere

    A chat assistant without a shell cannot use it, however cheap it is.

In a real test suite

Agent teams track context per task as closely as latency. Small changes in how tools report results can halve the cost of a workflow.

Whichever driver you choose, keep the task definition and the success check outside the agent, for example the order reference on the confirmation page, so you can compare runs fairly and tell when a cheaper setup starts failing more often.