print-stylesheet-tests
БесплатноБез исполняемых скриптовНе проверенUse when an app has a Print button or print stylesheet that is untested, or printed and PDF copies break in the wrong places. Tests print CSS with Playwright…
от testland★ 18 звёзд на GitHubОб этом скилле
print-stylesheet-tests
Per [MDN Paged Media], CSS Paged Media defines @page rules and
break-control properties for print output. Per the [Playwright
page.pdf docs], page.pdf() "generates PDFs using print CSS media
by default" - call emulateMedia first if you want screen styles
applied to PDF instead.
When to use
- App has a Print button or generates PDFs from Chromium.
- Print stylesheet exists but isn't tested - silent regressions cause customer complaints "the printed copy looks broken".
- Pre-deploy gate: page breaks fall in the right places, headers don't get orphaned at page bottom.
How to use
- Load the printable page in Playwright and call
page.emulateMedia({ media: 'print' })to activate the print stylesheet. - Assert screen-only chrome (nav, buttons) is hidden and print-only content (legal footers) is visible under print media.
- Generate the PDF with
page.pdf(), passingpreferCSSPageSize: truewhen CSS@pageowns the page size. - Assert page count for representative fixtures (standard invoice = 1 page, long invoice = 2) to catch overflow regressions.
- Extract text per page to prove
break-before/break-insiderules land chapter and section boundaries correctly. - Set
printBackground: truewhen branded headers or color fills must appear in the customer-facing PDF. - For letterhead margins and per-page geometry, pair with
pdf-snapshot-testeron the rendered page - see references/page-geometry.md.
Step 1 - Test @media print selectors activate
import { test, expect } from '@playwright/test';
test('navigation hidden when printing', async ({ page }) => {
await page.goto('https://localhost:3000/invoice/inv_001');
// Default media = screen → nav visible
await expect(page.locator('nav.app-nav')).toBeVisible();
// Switch to print
await page.emulateMedia({ media: 'print' });
await expect(page.locator('nav.app-nav')).toBeHidden();
});
emulateMedia activates @media print rules per [MDN Paged Media].
Step 2 - Test print-only content appears
test('print-only legal footer appears under print media', async ({ page }) => {
await page.goto('https://localhost:3000/invoice/inv_001');
await expect(page.locator('.print-only-legal')).toBeHidden();
await page.emulateMedia({ media: 'print' });
await expect(page.locator('.print-only-legal')).toBeVisible();
});
Step 3 - Generate PDF + verify @page size honored
test('PDF respects @page size: A4', async ({ page }) => {
await page.goto('https://localhost:3000/invoice/inv_001');
const pdf = await page.pdf({
preferCSSPageSize: true,
});
// Use a PDF inspector lib or pair with pdf-snapshot-tester
const dimensions = await getPdfDimensions(pdf);
expect(dimensions.format).toBe('A4');
});
Per the [Playwright page.pdf docs]: preferCSSPageSize: true lets
CSS @page { size: A4 } win over the API format option. Without
it, API wins.
Step 4 - Test page count
test('invoice fits on 1 page when standard line count', async ({ page }) => {
await page.goto('https://localhost:3000/invoice/standard');
const pdf = await page.pdf({ format: 'A4' });
const pageCount = await getPdfPageCount(pdf);
expect(pageCount).toBe(1);
});
test('invoice spills to 2 pages when many line items', async ({ page }) => {
await page.goto('https://localhost:3000/invoice/long');
const pdf = await page.pdf({ format: 'A4' });
const pageCount = await getPdfPageCount(pdf);
expect(pageCount).toBe(2);
});
Page count regressions ("invoice now needs 3 pages instead of 1") are the canonical print bug.
Step 5 - Test break-before / break-after / break-inside
CSS:
@media print {
h1.chapter { break-before: page; }
table.totals { break-inside: avoid; }
p { orphans: 3; widows: 3; }
}
Test that the chapter break shows up:
test('each chapter starts on new page', async ({ page }) => {
await page.goto('https://localhost:3000/manual');
const pdf = await page.pdf({ format: 'A4' });
const pageTexts = await extractTextPerPage(pdf);
// Chapter 1 on page 1, Chapter 2 on page 2, ...
expect(pageTexts[0]).toContain('Chapter 1');
expect(pageTexts[1]).toContain('Chapter 2');
});
Step 6 - printBackground for branded headers
By default printBackground: false - backgrounds (gradients,
images) don't render. Customer-facing PDFs usually need
printBackground: true:
test('branded header background appears', async ({ page }) => {
await page.goto('https://localhost:3000/branded-letter');
const pdf = await page.pdf({
printBackground: true,
format: 'A4',
});
const page1 = await renderPdfPage(pdf, 1);
expect(await hasBrandColorAtTop(page1)).toBe(true);
});
Per the [Playwright page.pdf docs]: printBackground defaults
false.
Advanced @page geometry
@page :first / :left / :right pseudo-class targeting and margin
verification (including t
Установить print-stylesheet-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл print-stylesheet-tests?
Use when an app has a Print button or print stylesheet that is untested, or printed and PDF copies break in the wrong places. Tests print CSS with Playwright print emulation and page.pdf(): @page size and margins, page breaks, orphans and widows, and print-only rules.
Как установить скилл print-stylesheet-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл print-stylesheet-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic