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.