Skip to content
cccskills
FreePublished on GitHub

print-stylesheet-tests

Test CSS print-media output via Playwright `page.emulateMedia({ media: 'print' })` + `page.pdf()` - `@page` rule (size, margin, orphans, widows), `@page :first / :left / :right` pseudo-classes, `break-before/after/inside`, `@media print` selector activation, page-break suppression on headings. Use when an app exposes a Print button or a print stylesheet exists but is untested, and users report the printed or PDF copy breaking in the wrong places while the on-screen page looks fine.

The English summary is being prepared. Showing the original description.

testland/qa13 stars(GitHub 13 + cccskills 0)
Works withPlaywright

Run score Not tested

See how to install

Files included (3)

  • SKILL.md8.2 KB
  • .tessl-plugin/plugin.json625 B
  • references/page-geometry.md1.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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

  1. Load the printable page in Playwright and call page.emulateMedia({ media: 'print' }) to activate the print stylesheet.
  2. Assert screen-only chrome (nav, buttons) is hidden and print-only content (legal footers) is visible under print media.
  3. Generate the PDF with page.pdf(), passing preferCSSPageSize: true when CSS @page owns the page size.
  4. Assert page count for representative fixtures (standard invoice = 1 page, long invoice = 2) to catch overflow regressions.
  5. Extract text per page to prove break-before / break-inside rules land chapter and section boundaries correctly.
  6. Set printBackground: true when branded headers or color fills must appear in the customer-facing PDF.
  7. For letterhead margins and per-page geometry, pair with pdf-snapshot-tester on 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 the CSS-vs-API margin precedence rule) are covered in references/page-geometry.md.

Worked example

Customers report a redesigned invoice prints with the totals table split across two pages, though it looks fine on screen.

  1. Point a Playwright test at /invoice/long and generate the PDF with page.pdf({ format: 'A4' }).
  2. getPdfPageCount(pdf) returns 3; the pre-redesign baseline test asserted toBe(2), so the count assertion fails and pins the regression.
  3. extractTextPerPage(pdf) shows the table.totals rows straddling the page 2 / page 3 boundary - the redesign dropped break-inside: avoid.
  4. Re-add @media print { table.totals { break-inside: avoid; } } to the stylesheet.
  5. Re-run: getPdfPageCount returns 2 and the totals text sits wholly on page 2, so both the page-count and per-page-text assertions pass.

Anti-patterns

Anti-patternWhy it failsFix
Test print stylesheet only by visually inspecting page.pdf() outputRegressions slip; not automatedPair with pdf-snapshot-tester (see references/page-geometry.md)
Skip preferCSSPageSize when CSS owns layoutAPI options override; CSS @page ignoredpreferCSSPageSize: true (Step 3)
Forget printBackground: trueBranded headers/colors missing in prod PDFsStep 6
Test only Chromium-rendered PDFWeasyPrint / wkhtmltopdf differ; cross-engine bugs slippdf-snapshot-tester references/cross-engine-regression.md covers cross-engine
Hard-code page-break tests against pixel positionsSlight font tweaks invalidateTest text content per page (Step 5)

Limitations

  • Playwright PDF generation uses Chromium's print path; WeasyPrint and wkhtmltopdf produce different output for the same HTML+CSS. Test the engine you actually ship with.
  • @page marks and bleeds descriptors per MDN Paged Media have limited browser support.
  • Some advanced @page features (running headers, generated content in page margins) are well-supported in WeasyPrint but limited in Chromium.

References

  • MDN Paged Media - @page, page pseudo-classes, break properties
  • Playwright page.pdf docs - options, default print media, preferCSSPageSize, printBackground
  • references/page-geometry.md - @page pseudo-classes and margin verification
  • pdf-snapshot-tester - sister skill for pixel-diff assertions on rendered PDF pages; its references/cross-engine-regression.md covers cross-engine HTML→PDF comparison

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Builds a CI gate that fails the build on **new** WCAG / a11y violations introduced by a PR while grandfathering pre-existing violations on a per-rule / per-page baseline. Aggregates verdicts from axe-core / pa11y / Lighthouse a11y / WAVE / IBM Equal Access scans. Use when a project has accumulated a11y debt and a strict "zero violations" gate would block every PR - the ratchet pattern lets the team ship while preventing regressions.

The English summary is being prepared. Showing the original description.

testland/qa13Updated Oct 20, 2026

Workflow skill that builds an A/B-test validity checklist from an experiment proposal, walking the canonical design-correctness gates - pre-registered OEC/power/guardrails, randomization unit + SRM check, assignment integrity, telemetry, peeking discipline, novelty/primacy, post-experiment SRM re-check - into a per-experiment checklist + sign-off form. Use when launching, auditing, or governing an experiment. For pitfall mechanics (guardrails, peeking) see experiment-results-interpreter's references; to read an already-valid result use experiment-results-interpreter; for per-SDK harness tests use experiment-sdk-testing - this gates DESIGN, not SDK code.

The English summary is being prepared. Showing the original description.

testland/qa13Updated Oct 20, 2026

The single install-flow skill: the reference contract for the PWA install flow (installability gate fields, `beforeinstallprompt` handshake, per-platform paths - Android WebAPK / iOS Share menu / Firefox no-op - and the `display-mode` post-install signal, in references/install-flow-reference.md) plus the build-an-X workflow that emits the Add-to-Home-Screen suite. Walks the four-stage timeline, emitting one test per gate cell per [web.dev/articles/install-criteria][install-criteria], the deferred-prompt → `prompt()` → `userChoice` chain per [web.dev/articles/customize-install][customize-install], the iOS Safari manual-metadata branch (`apple-touch-icon`) per [web.dev/learn/pwa/installation][learn-pwa], and the post-install `(display-mode: standalone)` MQ assertion. Output: a Playwright spec with per-stage cells plus a coverage matrix. Use when a PWA's manifest, icons, or install handler change, when install conversion drops at an unknown stage, or when triaging a flaky install assertion.

The English summary is being prepared. Showing the original description.

testland/qa13Updated Oct 20, 2026

Build-an-X workflow that uses an LLM to map existing tests to spec sections - given a spec doc + the test suite, the LLM identifies which tests cover which sections, surfaces uncovered sections (gap), and recommends specific tests to add. Output is a coverage matrix per spec ID. Scope is mapping tests that already exist and naming the gaps, not authoring tests for new acceptance criteria. Use when a spec doc and a test suite both exist but nobody can say which requirements are actually covered - before a release sign-off, an audit, or a decision about where to spend the next round of test effort.

The English summary is being prepared. Showing the original description.

testland/qa13Updated Oct 20, 2026

Generates tests from natural-language specs (acceptance criteria, user stories, requirements) using an LLM, with confidence scoring per test case (LLM self-assessment plus heuristics: assertion quality, naming, completeness), batching uncertain cases for human review, and integration with the team's existing test framework. Use when the user asks to generate unit tests from acceptance criteria, convert user stories to test cases, automate test creation from requirements, or augment a spec-driven test suite with AI-generated stubs that are then curated before merge.

The English summary is being prepared. Showing the original description.

testland/qa13Updated Oct 20, 2026

Configures Allure Report (test-runner adapter install, `allure-results` directory wiring, `categories.json` for failure classification, `history-trend.json` retention via the copy-history-between-runs pattern), runs the Allure CLI to convert `allure-results` to a static HTML site, and uploads the report as a CI artifact. Use when the team needs richer test reporting than JUnit XML - step-level attachments, per-test history, retry tracking, and severity / epic / feature labeling across framework-agnostic adapters (pytest, Jest, JUnit, TestNG, NUnit, Mocha). As a rich static HTML report generator, it is the open-source alternative to the sunset ExtentReports (JVM/.NET per-test HTML narrative); for hosted cross-run flakiness analytics rather than a static per-run report use currents-integration.

The English summary is being prepared. Showing the original description.

testland/qa13Updated Oct 20, 2026

See all skills by testland

Report a problem with this skill