Running Playwright Tests on a Schedule with Cron
`cd` into the project, call `npx playwright test` by absolute path, and rely on Playwright's bundled headless Chromium — no `Xvfb` needed, as long as you ran `npx playwright install` first.
The crontab line
0 */6 * * * cd /opt/tests && /usr/bin/npx playwright test >> /var/log/pw.log 2>&1
Run which npx for the path (with nvm it's under ~/.nvm/versions/node/.../bin/npx). cd into the project so Playwright finds playwright.config.ts.
No display server required
Playwright ships its own headless browsers, so you do not need Xvfb for the default headless run. Just make sure the browsers are installed: npx playwright install --with-deps.
Node via nvm
If Node came from nvm, source it first so node/npx resolve: . ~/.nvm/nvm.sh && cd /opt/tests && npx playwright test.
FAQ
How do I run Playwright tests from cron?
cd into the project and call npx: 0 */6 * * * cd /opt/tests && /usr/bin/npx playwright test. Install browsers once with npx playwright install.
Do I need Xvfb to run Playwright in cron?
No. Playwright uses bundled headless browsers, so the default headless run needs no display server.
Why is npx or node not found in my Playwright cron job?
If Node is from nvm it isn't on cron's PATH. Source ~/.nvm/nvm.sh first or use absolute paths.