Skip to content

Commit ac210cb

Browse files
Alexandre NédélecCopilot
andcommitted
refactor: use @playwright/cli for screenshots
Replace the Node.js playwright script with playwright-cli commands. playwright-cli is a token-efficient CLI tool designed for coding agents with simple commands like 'open', 'goto', 'screenshot', 'close'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 001d1e0 commit ac210cb

1 file changed

Lines changed: 30 additions & 43 deletions

File tree

.github/workflows/template-sync.md

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ pnpm run lint
146146

147147
## Step 6: Run the dev server and take screenshots
148148

149-
Install Playwright's Chromium browser, then start the dev server and take screenshots of the
150-
key pages. Save them to `.playwright-screenshots/` (this folder is not committed to git — it
151-
will be uploaded as a workflow artifact separately).
149+
Install `@playwright/cli` (the Playwright CLI tool designed for coding agents), then start the
150+
dev server and take screenshots of key pages. Save them to `.playwright-screenshots/` (this
151+
folder is not committed to git — it will be uploaded as a workflow artifact separately).
152152

153153
```bash
154-
pnpm exec playwright install chromium --with-deps
154+
npm install -g @playwright/cli@latest
155+
```
156+
157+
Start the dev server in background and wait for it to be ready:
155158

159+
```bash
156160
# Start dev server in background
157161
pnpm dev &
158162
DEV_PID=$!
@@ -165,47 +169,30 @@ for i in $(seq 1 30); do
165169
done
166170
```
167171

168-
Write a Node.js script to `.playwright-screenshots/take-screenshots.mjs` with this content:
169-
170-
```javascript
171-
import { chromium } from 'playwright';
172-
import { mkdirSync } from 'fs';
173-
174-
mkdirSync('.playwright-screenshots', { recursive: true });
175-
176-
const browser = await chromium.launch();
177-
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
178-
179-
const pages = [
180-
['home', 'http://localhost:3000'],
181-
['posts', 'http://localhost:3000/posts'],
182-
['goodies', 'http://localhost:3000/goodies'],
183-
['speaking', 'http://localhost:3000/speaking'],
184-
['tags', 'http://localhost:3000/tags'],
185-
['about', 'http://localhost:3000/about'],
186-
];
187-
188-
for (const [name, url] of pages) {
189-
try {
190-
await page.goto(url, { waitUntil: 'networkidle', timeout: 15000 });
191-
await page.screenshot({
192-
path: `.playwright-screenshots/${name}.png`,
193-
fullPage: false,
194-
});
195-
console.log(`✅ Screenshot saved: ${name}`);
196-
} catch (e) {
197-
console.error(`❌ Failed to screenshot ${name}: ${e.message}`);
198-
}
199-
}
200-
201-
await browser.close();
202-
console.log('Done.');
203-
```
204-
205-
Then run the screenshot script and stop the dev server:
172+
Create the screenshots directory and take screenshots with `playwright-cli`:
206173

207174
```bash
208-
node .playwright-screenshots/take-screenshots.mjs
175+
mkdir -p .playwright-screenshots
176+
177+
playwright-cli open http://localhost:3000
178+
playwright-cli screenshot --filename=.playwright-screenshots/home.png
179+
180+
playwright-cli goto http://localhost:3000/posts
181+
playwright-cli screenshot --filename=.playwright-screenshots/posts.png
182+
183+
playwright-cli goto http://localhost:3000/goodies
184+
playwright-cli screenshot --filename=.playwright-screenshots/goodies.png
185+
186+
playwright-cli goto http://localhost:3000/speaking
187+
playwright-cli screenshot --filename=.playwright-screenshots/speaking.png
188+
189+
playwright-cli goto http://localhost:3000/tags
190+
playwright-cli screenshot --filename=.playwright-screenshots/tags.png
191+
192+
playwright-cli goto http://localhost:3000/about
193+
playwright-cli screenshot --filename=.playwright-screenshots/about.png
194+
195+
playwright-cli close
209196
kill $DEV_PID 2>/dev/null || true
210197
```
211198

0 commit comments

Comments
 (0)