In the last post I explained why Playwright CLI is a better fit than Playwright MCP for AI coding agents. So before we talk about workflows, debugging, or best practices, let's make the tool clear.
- What is it?
- How do you install it?
- And how do you run one simple command against a real website?
────────────────────────────────────────
🟢 𝐖𝐡𝐚𝐭 𝐏𝐥𝐚𝐲𝐰𝐫𝐢𝐠𝐡𝐭 𝐂𝐋𝐈 𝐀𝐜𝐭𝐮𝐚𝐥𝐥𝐲 𝐈𝐬
Playwright CLI is a command-line tool for controlling a browser.
You run commands in the terminal, and Playwright CLI can:
➜ Open a website
➜ Click buttons
➜ Fill inputs
➜ Press keys
➜ Take screenshots
➜ Read a page snapshot
It was designed for AI coding agents. But it is not only for AI. You can use it yourself from the terminal to check that the browser opens, the page loads, and the command returns useful page information.
────────────────────────────────────────
🧠 𝐇𝐨𝐰 𝐈𝐭 𝐅𝐢𝐭𝐬 𝐖𝐢𝐭𝐡 𝐀𝐈 𝐂𝐨𝐝𝐢𝐧𝐠 𝐀𝐠𝐞𝐧𝐭𝐬
The workflow is simple:
1. You ask the AI agent to inspect a page or debug a UI flow.
2. The agent runs Playwright CLI commands in the terminal.
3. Playwright CLI controls the browser.
4. The agent reads the result and decides what to do next.
This does not replace Selenium, Cypress, or Playwright Test. It acts as a new layer on top of the testing frameworks.
────────────────────────────────────────
🍎 𝐈𝐧𝐬𝐭𝐚𝐥𝐥 𝐏𝐥𝐚𝐲𝐰𝐫𝐢𝐠𝐡𝐭 𝐂𝐋𝐈 𝐎𝐧 𝐌𝐚𝐜
You need `Node.js` and `npm ` first.
If you already have them, check in Terminal:
────────────────
> node -v
────────────────
> npm -v
────────────────
If those commands do not work, install Node.js LTS first:
────────────────
> brew install node
────────────────
Once `node` and `npm` work, install Playwright CLI:
────────────────
> npm install -g @playwright/cli@latest
────────────────
Then verify it:
────────────────
> playwright-cli --version
────────────────
You can also print the available commands:
────────────────
> playwright-cli --help
────────────────
Now go to the project where you want to use it:
────────────────
> cd your-project-folder
────────────────
Run the project setup:
────────────────
> playwright-cli install
────────────────
Install the browsers:
────────────────
> playwright-cli install-browser
────────────────
────────────────────────────────────────
🌐 𝐑𝐮𝐧 𝐘𝐨𝐮𝐫 𝐅𝐢𝐫𝐬𝐭 𝐁𝐫𝐨𝐰𝐬𝐞𝐫 𝐂𝐨𝐦𝐦𝐚𝐧𝐝
Now test it on a real page.
Use Skool url an an example:
────────────────
────────────────
Headed mode means the browser opens visually on your screen. You can see whether the browser actually opened and whether the page loaded.
If the page opens, run:
────────────────
> playwright-cli snapshot
────────────────
This command asks Playwright CLI to read the current page html. The result should include page information such as visible text, links, buttons, inputs, and element references.
That is the output an AI coding agent can use. It can look at the snapshot and decide what to click, what field to fill, or what locator to use in a test.
────────────────────────────────────────
✅ 𝐖𝐡𝐚𝐭 𝐀 𝐆𝐨𝐨𝐝 𝐒𝐞𝐭𝐮𝐩 𝐋𝐨𝐨𝐤𝐬 𝐋𝐢𝐤𝐞
A good setup means you can do this:
1. Run `playwright-cli --version`
2. Run `playwright-cli install` inside your project
4. Run `playwright-cli snapshot`
5. Get useful page information back
That is enough for the first check that proves that Playwright CLI can control a browser and return page information.
────────────────────────────────────────
🔴 𝐂𝐨𝐦𝐦𝐨𝐧 𝐈𝐧𝐬𝐭𝐚𝐥𝐥𝐚𝐭𝐢𝐨𝐧 𝐏𝐫𝐨𝐛𝐥𝐞𝐦𝐬
If it fails, check these first:
∙ `Node.js` is not installed
∙ `npm` is not available in your terminal
∙ `playwright-cli` is not on your PATH
∙ You ran the command outside the project folder
∙ The browser was not installed
∙ Your AI agent uses a different terminal environment
The last one matters. Sometimes a command works in your terminal but fails when the AI agent runs it.
That usually means the agent is using a different shell, path, or working directory. Try opening a new Terminal window, going to the project folder, and trying again.
────────────────────────────────────────
📌 Want to learn how to use AI coding agents for real test automation work?
Join the AI AutoTest Live Workshop.
This is a 6-hour combination of live theory, hands-on practice, and real workflows focused on using AI coding agents for test automation.