slop audit
Blog post 92 / Launch readiness

Download link testing: verify files before launch

Use download link testing to check HTML download behavior, Content-Disposition, filenames, and saved file contents with curl and Playwright before launch.

By Slop Audit · 7 min read

Download link testing should prove that a visitor receives the file your page promises. A successful HTTP response is only the first check: the browser might open a document instead of saving it, suggest an unhelpful filename, or save an HTML error page with a CSV extension. Before launching a portfolio, documentation site, or student project, test the visible link, delivered response, browser download, and saved contents together.

This guide uses a small, public CSV checklist as a reproducible example. Run the download tests against files and environments you control. Keep private exports, purchase flows, and large generated archives in a separate test plan with appropriate test accounts and data.

Define the download link testing contract

Write down the expected result before changing markup or headers:

  • Source page: /resources.
  • Visible link: “Download launch checklist (CSV)”.
  • File URL: /downloads/launch-checklist.csv on the same origin.
  • Successful response: 200 with a text/csv media type.
  • Browser behavior: save an attachment named launch-checklist.csv.
  • File contents: the three lines below, encoded as UTF-8 with LF line endings and a final newline.
check,owner
Metadata,Developer
Keyboard path,Reviewer

Create that file in your application's public assets or serve those exact bytes from a read-only endpoint. Configure the response headers shown later. The example test deliberately uses an exact fixture; a changing export needs assertions about its schema, expected records, and test data instead.

A download that intentionally opens a PDF preview has a different contract. Label it “View project report (PDF)” and verify the preview separately. Decide which experience you want before treating the absence of a download event as a defect.

Use a real link and the HTML download attribute

Put this link on the resources page:

<a href="/downloads/launch-checklist.csv" download="launch-checklist.csv">
  Download launch checklist (CSV)
</a>

The anchor provides a destination without a JavaScript click handler. Its text names the resource and the format. W3C's descriptive link text technique explains why people need to distinguish destinations; it also notes that identifying a file format is useful, although that detail is not itself required by the linked success criterion.

Keep the visible wording in the accessible name. An unrelated aria-label="Get file" can replace the more useful text. See the accessible name testing guide when an icon or reusable link component changes what assistive technology receives.

The download attribute is a download hint, not proof that the file was saved. MDN documents that it applies to same-origin URLs and supported blob/data URLs. A different subdomain is a different origin. If a CDN serves the file, configure its response deliberately and test the browser outcome rather than assuming this attribute controls an external host.

Avoid replacing the anchor with a clickable div. Check that Tab reaches the link, its focus indicator is visible, and Enter activates it. The website CTA checklist covers the surrounding label and first-task review; the delivery checks below establish whether the download itself works.

Set Content-Disposition on the file response

For this fixture, deliver these headers on the actual CSV response:

Content-Type: text/csv; charset=utf-8
Content-Disposition: attachment; filename="launch-checklist.csv"

attachment asks the browser to handle the response as a download. inline asks for normal display, where supported. The filename is a suggestion to the browser. MDN's Content-Disposition reference also documents filename* for encoded international filenames and explains filename precedence when a response header and an HTML attribute disagree.

Keep the header and attribute aligned. Put headers on the file route, not only on /resources. With static hosting, use the platform's route-header configuration; with a generated response, set them where that response is created. Inspect the delivered result after the CDN or proxy has processed it.

Do not fix an HTML response by forcing its media type to text/csv. A missing asset may have fallen through to the single-page application shell. Repair the path or deployment rule so it serves the intended bytes. The broken link testing guide covers route failures, while a file-content assertion catches this misleading 200 response.

Inspect the deployed response with curl

Use a GET request to save both headers and body in a temporary directory:

workdir=$(mktemp -d)
curl --fail --show-error --silent --location --max-redirs 5 \
  --dump-header "$workdir/headers.txt" \
  --output "$workdir/checklist.csv" \
  --write-out 'status=%{http_code} final=%{url_effective}\n' \
  https://example.com/downloads/launch-checklist.csv
cat "$workdir/headers.txt"
cat "$workdir/checklist.csv"

Replace the example URL with your controlled deployment. For this tiny text fixture, inspect the saved body and confirm the expected rows. Do not use cat for unknown binary downloads; open trusted documents with the intended application in your test environment.

If redirects occurred, the header file contains multiple response blocks. Check the final block and the printed final URL. A redirect to a sign-in page explains why a supposedly public download returns HTML. A 404 suggests a missing file or wrong asset path. A 200 containing the application shell suggests a rewrite problem. A correct body displayed in a browser tab points toward download handling rather than missing content.

This request checks delivery independently of the page. It does not prove that the rendered link has the right destination or that a browser will present the intended filename. Test that connection next.

Add a Playwright download test

Use this test in an existing Playwright Test project. Set DOWNLOAD_TEST_BASE_URL to your controlled deployment, publish /resources with the exact link above, and serve the fixture with the specified headers. No authentication state is needed for this public example.

import { test, expect } from '@playwright/test';
import { readFile } from 'node:fs/promises';

const baseURL = process.env.DOWNLOAD_TEST_BASE_URL;
if (!baseURL) throw new Error('Set DOWNLOAD_TEST_BASE_URL');

const expectedCsv = 'check,owner\nMetadata,Developer\nKeyboard path,Reviewer\n';

test('public checklist downloads with the promised name and bytes', async ({ page }, testInfo) => {
  const sourceURL = new URL('/resources', baseURL).href;
  const fileURL = new URL('/downloads/launch-checklist.csv', baseURL).href;
  await page.goto(sourceURL);
  const link = page.getByRole('link', {
    name: 'Download launch checklist (CSV)', exact: true,
  });
  await expect(link).toBeVisible();
  await expect(link).toHaveAttribute('href', '/downloads/launch-checklist.csv');
  await expect(link).toHaveAttribute('download', 'launch-checklist.csv');

  const response = await page.request.get(fileURL);
  expect(response.status()).toBe(200);
  expect(response.url()).toBe(fileURL);
  expect(response.headers()['content-type']).toMatch(/^text\/csv(?:;|$)/i);
  expect(response.headers()['content-disposition']).toMatch(/^attachment(?:;|$)/i);
  expect(await response.body()).toEqual(Buffer.from(expectedCsv, 'utf8'));

  await link.focus();
  await expect(link).toBeFocused();
  const downloadPromise = page.waitForEvent('download');
  await link.press('Enter');
  const download = await downloadPromise;
  const savedPath = testInfo.outputPath('checklist.csv');
  await download.saveAs(savedPath);
  expect(await download.failure()).toBeNull();
  expect(download.suggestedFilename()).toBe('launch-checklist.csv');
  expect(await readFile(savedPath)).toEqual(Buffer.from(expectedCsv, 'utf8'));
});

Register the event wait before activation so a fast download cannot finish before the listener exists. Save the file before the browser context closes; Playwright deletes its temporary downloads when that context closes. The official Playwright downloads guide explains this lifecycle, and the Download API defines filename, failure, and save operations.

This test checks two things separately: the endpoint delivers the expected response, and the page initiates a browser download containing the same fixture. It deliberately fails on redirects because this contract uses one stable public asset URL. Adjust that expectation if your approved delivery path uses a CDN redirect, and assert its intended final destination.

The focus call isolates Enter activation; it does not prove the link is reachable through normal Tab order. Complete that manual keyboard check too. Run the test in your supported browser projects and at narrow and desktop widths. For PDFs or ZIPs, replace the CSV comparison with a suitable parser and assertions about the expected document or archive entries. A filename or a nonempty body alone cannot establish that the file is usable.

Check the surrounding public page with Slop Audit

Run a Slop Audit on the public resources page before sharing it. Review available evidence for action labels, placeholder destinations, accessible names, axe violations, sampled keyboard focus, and mobile layout. Fix observed page issues, then rescan the deployed URL.

Slop Audit's safe first-task evaluator does not invoke download actions. An untested download is a coverage limit, not proof of success or failure. The audit does not validate your saved filename, file contents, private export permissions, or document accessibility. Keep the controlled download test alongside the public-page report so those release decisions have their own evidence.

For release sign-off, record the source URL, file URL, filename, expected content version, tested browsers, and result. Open the downloaded file once in its intended application. Repeat the check when replacing the asset or changing hosting rules; the website regression testing guide explains how to retain a useful release baseline.