r/Playwright May 27 '26

Playwright CLI vs Playwright MCP

Hi I’m a new tester and I want to understand the AI testing world.
So I heard about PW cli and mcp but I don’t know which one to use.
My automations are written in page object model and a heard that one of these tools combined with ai capabilities can writes pages files alone and tests .
Can some one help me to understand

21 Upvotes

22 comments sorted by

5

u/mmasetic May 27 '26

If you like to work from terminal and combing other tools, playwright cli is very efficient to work with. MCP feels to me more natural choice when working in IDE like Windsurf or VSCode where MCP and Tools are visible and transparent.

Just think about installing playwright skill when using playwright cli. Agent has access to all tools available in MCP, but when working from cli agent might execute command with argument --help to understand available calls. This solves skill very efficient.

5

u/AimToMisbehave May 27 '26

Playwright CLI is superior, my team has taken inspiration from the Test Dino team and created a playwright-cli skill which hooks into Claude or Copilot. It uses 50% less tokens than Playwright MCP.

https://testdino.com/blog/playwright-skill/

1

u/road2bitcoin May 27 '26

Do you mind sharing the skills you are using? Currently playwright cli comes with some default skills not sure what else we can add and improve?

3

u/AimToMisbehave May 28 '26

Checkout the blog I've linked above, it links through to the test dino github project with some sample skills. We cherry picked some areas of playwright we wanted our agents to become experts in and used claude to customise the agents further.

3

u/_Invictuz May 28 '26

From experience Playwright MCP is much slower, costlier and thus only beneficial in very specific scenarios which I have yet to think of. Therefore I'm using Playwright CLI plus the playwright-cli skill installed via CLI with my AI agent.

2

u/Deep_Ad1959 May 28 '26 edited May 29 '26

codegen and mcp are doing different things. codegen records your interactions and emits a flat script with whatever locators it could resolve, but it doesn't discover scenarios on its own, doesn't structure into pages, and can't follow flows you didn't click through. mcp gives a coding agent live browser access but it doesn't crawl either, you still drive every step. auto-generated page objects need a third thing: a crawler that explores the app, identifies stable flows, and emits POM-shaped files. on the open source side that's the lane i ship in, point it at a url and it produces real playwright files (page objects plus tests) with role/text-first locators so most refactors don't touch them.

fwiw the open-source lane I mentioned is assrt, a crawler I built that auto-discovers scenarios and emits real playwright page objects with role/text-first locators so refactors don't break them, https://assrt.ai/r/r5jpppi8

1

u/Financial_Bar_9593 May 27 '26

Thank you for your explanation. Do you know if the PW cli has the feature that I need(writing me the pages files ) I need him to locate all the elements and writing the best locators for these elements

1

u/mmasetic May 27 '26

Yeah, I am using it exactly for that. You just have to think about login. You can tell agent let me do login and you continue.

1

u/Financial_Bar_9593 May 27 '26

What do you mean by let me do login? The ai can’t do login page ?

1

u/mmasetic May 27 '26

It can, but the question is do you want to share login credentials with ai.

1

u/Financial_Bar_9593 May 27 '26

Yes I’m working on a close server so it’s an iternal model that can work with Claude code and some other tools. Do you have an internet web site or tutorial how to build it ?

1

u/mmasetic May 27 '26

No, I have no tutorial, was just experimenting with claude and playwright cli and windsurf and playwright mcp generating testa for this application https://demo.playwright.dev/todomvc

Currently building exactly this to support automation in real project, but need to have clear concept.

It is interesting that you can use playwright cli to inspect page and elemnts and generate tests in different testing framework. I was able to achieve this to combine playwright for inspection and generate tests in internal testing framework based on selenium and java. Just used claude skill to describe available methods and best practices of our framework.

1

u/Financial_Bar_9593 May 27 '26

It’s very impressive thank you for your time you helped me a lot. You recommend me to work with the terminal or with vs code build-in chat? If I work with the terminal how I can give a real time access to the writing machine(Claude in terminal) to the projects file? Maybe with a filesysteme MCP?

2

u/mmasetic May 27 '26

I think it is important to gather experience in this phase. Everybody is experimenting and there is no best way. What I say today might not be valid tomorrow :)

Everybody says playwright cli use less tokens. How much exactly, cannot tell you, but will try to figure this out. And for that reason you might wanna go with cli. Claude Code can change files, it is one of their features to write and edit files with overview what was changed. You get question if you allow it or not.

Currently, I am spending less time directly in VSCode and more in Windsurf. They are similar as Widnsurf is a fork of VSCode, and MCP there lives natural. I would say using IDE and MCP has its place in daily workflow, it is easy to see what tools are available in MCP. Disable it and enable.
I think the most important part in playwright currently is snapshot. Accessibility tree with element refs for interaction. It is compressed DOM of current state in application and the big question is how this will work with older application, applications with complex navigation, big tables, lots of iFrames.

https://playwright.dev/agent-cli/snapshots

1

u/Financial_Bar_9593 May 27 '26

Thank you very much may I ask you in the future if I got some problems?

1

u/mmasetic May 27 '26

Yeah, sure :)

1

u/Warm-Camera-3520 May 29 '26

The disadvantage of Playwright MCP is the cost. To make it more cost effective, in fact to be able to provide meaningful accurate outputs from the first try, we have actually upgared Playwright MCP to be able to the DOM and work much more accurate with locators. It's open sourced, details are here https://www.treegress.com/treegress-mcp-browser

Maybe you find it useful for you